将 CSS 类添加到 Html.BeginForm()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13984029/
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-08-29 21:06:00  来源:igfitidea点击:

Adding CSS class to Html.BeginForm()

.netcssformsasp.net-mvc-4html-helper

提问by Vishal

How to add class attribute for following situation (Using ReturnUrl only):

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

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))
{
}

I want something like this:

我想要这样的东西:

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }, new { @class = "login-form" })) 
{
}

回答by moribvndvs

There is an overload for that, if you supply the controller action, name, and form method.

如果您提供控制器操作、名称和表单方法,则有一个重载。

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

回答by p4rds

Html.BeginForm("Index", "EIApplication", FormMethod.Post, new { enctype = "multipart/form-data", **@class = "nea-forms"** })

回答by Frédéric

Or simply using html :

或者简单地使用 html :

<form action="/ActionName/ControllerName" method="post" class="login-form">

</form>