将CSS类添加到Html.BeginForm()

Vis*_*hal 71 .net css forms html-helper asp.net-mvc-4

如何为以下情况添加类属性(仅使用ReturnUrl):

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))
{
}
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }, new { @class = "login-form" })) 
{
}
Run Code Online (Sandbox Code Playgroud)

Hac*_*ese 146

如果您提供控制器操作,名称和表单方法,则会出现重载.

@using (Html.BeginForm("ActionName", "ControllerName", 
            new { ReturnUrl = ViewBag.ReturnUrl }, 
            FormMethod.Post, new { @class="login-form" }))
{
  etc.
}
Run Code Online (Sandbox Code Playgroud)

  • 该方法最常见的用途是`Html.BeginForm()`,因此,我希望微软可以调用`Html.BeginForm(new {@ class ="something"})`而无需关心所有其他参数. (23认同)
  • 谢谢......这就是我需要的...... !! (2认同)