MVC Html.BeginForm使用区域

Mar*_*iko 49 asp.net-mvc html-helper

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

area: Security
controller: AccountController
method: logon
Run Code Online (Sandbox Code Playgroud)

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

mos*_*ers 89

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

@using (Html.BeginForm("LogOff", "Account", new { area = ""}, FormMethod.Post, new { id = "logoutForm" }))
Run Code Online (Sandbox Code Playgroud)

  • 使用'area'的*附加*匿名类型+1,而不是像我尝试的那样将'area'添加到带有'id'的匿名类型. (6认同)

小智 78

试试这个:

Html.BeginForm("logon", "Account", new {area="Security"})
Run Code Online (Sandbox Code Playgroud)


tva*_*son 7

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

@using (Html.BeginForm( new { area = "security", controller = "account", action = "logon" } ))
{
   ...
}
Run Code Online (Sandbox Code Playgroud)


Sam*_*Son 5

将此用于具有 HTML 属性的区域

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

   ...

}
Run Code Online (Sandbox Code Playgroud)