[英]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
. 如果未为
url
提到的参数指定值,则default
路由值显示请求必须到达的位置。 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')]
如果您的项目中有授权,请尝试使用
'[AllowAnonymous]'
或Authorize(Roles='a user role')]
装饰您要尝试的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.