Adding CSS class to Html.BeginForm()

て烟熏妆下的殇ゞ 提交于 2019-12-03 02:31:17

问题


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

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

I want something like this:

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

回答1:


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.
}



回答2:


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



回答3:


Or simply using html :

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

</form>


来源:https://stackoverflow.com/questions/13984029/adding-css-class-to-html-beginform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!