MVC Html.BeginForm使用区域

时间:2011-03-12 15:46:20

标签: asp.net-mvc html-helper

我正在使用MVC区域并且在一个名为“Test”的区域中的视图中我希望有一个表单可以发布到以下方法:

area: Security
controller: AccountController
method: logon

如何使用Html.BeginForm实现这一目标?可以吗?

6 个答案:

答案 0 :(得分:86)

对于那些想知道如何使用默认mvc4模板

的人
@using (Html.BeginForm("LogOff", "Account", new { area = ""}, FormMethod.Post, new { id = "logoutForm" }))

答案 1 :(得分:76)

试试这个:

Html.BeginForm("logon", "Account", new {area="Security"})

答案 2 :(得分:6)

尝试将区域,控制器和操作指定为RouteValues

@using (Html.BeginForm( new { area = "security", controller = "account", action = "logon" } ))
{
   ...
}

答案 3 :(得分:4)

将此用于包含HTML属性的区域

@using (Html.BeginForm(
      "Course", 
      "Assign", 
      new { area = "School" }, 
      FormMethod.Get, 
      new { @class = "form_section", id = "form_course" })) 
{

   ...

}

答案 4 :(得分:3)

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

答案 5 :(得分:0)

对于Ajax BeginForm,我们可以使用它

Ajax.BeginForm("IndexSearch", "Upload", new { area = "CapacityPlan" }, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = updateTarget }, new { id = "search-form", role = "search" })