8

is there some way to share a partial razor view between areas?

For example a login partial, it is found if i use @Html.Partial("_LoginPartial") but the URLs Html.ActionLink generates are local to the calling area (even though the partial itself is not part of the area).

_LoginPartial.cshtml is in /Views/Shared/_LoginPartial.cshtml
Calling view is inside /Areas/Somearea/Views

Links generated are like: http://example.com/Somearea/Account/Login
But should always be: http://example.com/Account/Login

Partial view source:

@if(Request.IsAuthenticated) {
    <text>Welcome <b>@Context.User.Identity.Name</b>!
    [ @Html.ActionLink(@Messages.Logout, "Logout", "Account") ]</text>
}
else {
    @:[ @Html.ActionLink(@Messages.Login, "Login", "Account") ]
}

Thanks

Fionn
  • 10,975
  • 11
  • 54
  • 84

1 Answers1

9

You can specify the area (or lack of one) in the ActionLink() method:

Html.ActionLink(@Messages.Logout, "Logout", "Account", new { Area = "" }, new{})

This will ensure the link does not resolve to a URL within the current area.

Jon
  • 4,925
  • 3
  • 28
  • 38