我的 Razor Layout View 中有以下代码段(由我的应用程序中的所有 View 共享):
@using (Html.BeginForm("Logout", "Account", FormMethod.Post, new { id = ViewIDs.Shared._AuthenticationPartial.LogoutForm })) {
这适用于我的主页和帐户 View ,即它呈现了一个发布到 ~/Account/Logout 的表单。但是,当与名为“Person”的区域内的 View 一起使用时,它突然发布到 ~/Person/Account/Logout。
现在,我能够解决这个问题如下:
@using (Html.BeginForm("Logout", "Account", new { area = "" }, FormMethod.Post, new { id = ViewIDs.Shared._AuthenticationPartial.LogoutForm })) {
这是执行此操作的正确方法,即根据定义默认区域是当前区域吗?还是我的应用程序中存在配置问题?
最佳答案
这是正确的方式。 ASP.NET MVC 隐式地使用 HTML 帮助程序中的当前路由值。这也是您在链接到同一 Controller 中的操作时只需说明操作名称的方法。如果您要链接到另一个区域,则必须像这样说明。
关于asp.net-mvc - Html.BeginForm 的默认区域是否始终是 ASP.NET MVC 中的当前区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16970984/