ASP.net MVC - Sharing partials between areas
Asked Answered
L

1

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

Log answered 5/3, 2011 at 0:5 Comment(0)
D
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.

Duong answered 5/3, 2011 at 0:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.