【问题标题】:Is the default area for Html.BeginForm always the current area in ASP.NET MVC?Html.BeginForm 的默认区域是否始终是 ASP.NET MVC 中的当前区域?
【发布时间】:2013-06-02 23:40:26
【问题描述】:

我的 Razor 布局视图(由我的应用程序中的所有视图共享)中有以下代码:

@using (Html.BeginForm("Logout", "Account", FormMethod.Post, new { id = ViewIDs.Shared._AuthenticationPartial.LogoutForm })) {

这适用于我的主页和帐户视图,即它呈现了一个发布到 ~/Account/Logout 的表单。但是,当与名为“Person”的区域内的视图一起使用时,它会突然发布到 ~/Person/Account/Logout。

现在,我可以按如下方式解决此问题:

@using (Html.BeginForm("Logout", "Account", new { area = "" }, FormMethod.Post, new { id = ViewIDs.Shared._AuthenticationPartial.LogoutForm })) {

这是执行此操作的正确方法吗,即,根据定义,默认区域是当前区域吗?还是我的应用程序有配置问题?

【问题讨论】:

  • 是的,这是正确的方法。您需要new { area = "" },因为默认区域是当前区域。

标签: asp.net-mvc asp.net-mvc-routing asp.net-mvc-areas


【解决方案1】:

这是正确的方法。 ASP.NET MVC 隐式使用 HTML 帮助程序中的当前路由值。这也是您在链接到同一控制器中的操作时只需声明操作名称的方式。如果您要链接到另一个区域,则必须这样声明。

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 2011-06-19
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多