Reputation: 1908
I am working with a default MVC5 Web application with the Web Api 'extension'. The solution comes with a 'web' Account controller, 'web' Home controller, a 'api' Values controller as well as a Help area with its own controller. The help controller details my api in html.
This is all default.
My issue is when I am in the Help area some of my action links (on the top menu) do not work. I expected the action on the top menu (Login, ect) to return to the default non-area routes, they did not. They instead redirected to the Help area. The "Application Name" that navigates to root works but Contact,About,Login,Register (ext) do not.
I have tried changing the action links to point to 'null' area, but that does not help.
@Html.ActionLink("Home", "Index", "Home", new { area = "" }, null)
The Action Links do not have the correct URI when I am within the Help area. When I mouse over the home action link it redirects me to localhost:port/Help. I would Like the action links to redirect back to the default controller routes (No area, Home/Account controller).
LoginPartial
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<ul class="nav navbar-nav navbar-right">
<li>
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
}
}
else
{
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink", area = "" })</li>
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink", area = "" })</li>
</ul>
}
Upvotes: 0
Views: 1530
Reputation: 2316
The only thing I can identify as the possible culprit in the LoginPartial
is the area
property set in the htmlAttributes
not the routeValues
. However I'm guessing this could have been from trying different things.
Modifying the routeValues
seems to be working for me though:
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<ul class="nav navbar-nav navbar-right">
<li>
@Html.ActionLink("Hello " + User.Identity.GetName() + "!", "Manage", "Account", routeValues: new { area = "" }, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
}
}
else
{
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: new { area = "" }, htmlAttributes: new { id = "registerLink" })</li>
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: new { area = "" }, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
Upvotes: 1