asp.net-mvc MVC Html.BeginForm 使用区域

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5283518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:59:09  来源:igfitidea点击:

MVC Html.BeginForm using Areas

asp.net-mvchtml-helper

提问by Mariko

I'm using MVC areas and on a view that's in an area called "Test" I would like to have a form that posts to the following method:

我正在使用 MVC 区域,并且在一个名为“测试”的区域中的视图上,我想要一个发布到以下方法的表单:

area: Security
controller: AccountController
method: logon

How can I make this happen with Html.BeginForm? Can it be done?

如何使用 Html.BeginForm 实现这一点?可以做到吗?

回答by mosesfetters

For those of you that want to know how to get it to work with the default mvc4 template

对于那些想知道如何让它与默认的 mvc4 模板一起工作的人

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

回答by Nam Le

Try this:

尝试这个:

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

回答by tvanfosson

Try specifying the area, controller, action as RouteValues

尝试将区域、控制器、动作指定为 RouteValues

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

回答by SamHymanSon

Use this for area with HTML Attributes

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

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

   ...

}

回答by Mohammad Karimi

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

回答by Sumesh Es

For Ajax BeginForm we can use this

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

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