Fab*_*ied 7 asp.net-mvc asp.net-mvc-routing asp.net-mvc-areas
我的Razor Layout视图中有以下代码(由我的应用程序中的所有视图共享):
@using (Html.BeginForm("Logout", "Account", FormMethod.Post, new { id = ViewIDs.Shared._AuthenticationPartial.LogoutForm })) {
Run Code Online (Sandbox Code Playgroud)
这与我的家庭和帐户视图一起工作正常,即它呈现了一个发布到〜/ Account/Logout的表单.但是,当与名为"Person"的区域内的视图一起使用时,它会突然发布到〜/ Person/Account/Logout.
现在,我能够解决这个问题如下:
@using (Html.BeginForm("Logout", "Account", new { area = "" }, FormMethod.Post, new { id = ViewIDs.Shared._AuthenticationPartial.LogoutForm })) {
Run Code Online (Sandbox Code Playgroud)
这是否是正确的方法,即根据定义当前区域的默认区域?或者我的应用程序中存在配置问题?
这是正确的方式。ASP.NET MVC 隐式使用 HTML 帮助程序中的当前路由值。这也是您在链接到同一控制器中的操作时只需声明操作名称即可避免的方法。如果您要链接到其他区域,则必须这样声明。
| 归档时间: |
|
| 查看次数: |
2254 次 |
| 最近记录: |