简体   繁体   中英

How to link Url.Action to a specific controller method

I have a menu with a number of selectable options within the menu, but for some reason if I select any of these items I am always redirected to the controller method of the last action which is the logout page.

My code for the list is the following:

<li class="edit">
    <i class="icon fa fa-cog"></i>
    <a href="@Url.Action("Index", "Manage")">My Account</a>
</li>

<li class="edit">
     <i class="icon fa fa-cog"></i>
     <a href="@Url.Action("Users", "Administrator")">Admin Tool</a>
</li>

<li class="edit">
     @using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" })){
    @Html.AntiForgeryToken()
    <a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
}

All of those actions happen to always go the the logout method no matter the order that I place them in.

Also I do not know whether this affects anything, however in my route config I have the following:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Account", action = "Index", id = UrlParameter.Optional }
        );

Maybe the reason that the controller methods are not found is because the route only mentions the account controller?

Nope, that's should not be a problem. The default route values shows where the request must go if no values are specified for the parameters mentioned in the url . If you have authorization in your project, try decorating the actions you are trying to get to with the '[AllowAnonymous]' or Authorize(Roles='a user role')]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM