Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding CSS class to Html.BeginForm()

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" }))  { } 
like image 914
Vishal Avatar asked Dec 21 '12 03:12

Vishal


People also ask

What is HTML BeginForm ()?

BeginForm(HtmlHelper) Writes an opening <form> tag to the response. The form uses the POST method, and the request is processed by the action method for the view. BeginForm(HtmlHelper, String, String, Object, FormMethod, Object)

Can we use multiple BeginForm in MVC?

Thanks for your help ! Multiple form tags should work fine in MVC unless they are nested.

How many parameters are generally used in HTML BeginForm?

BeginForm() method has three arguments, these are actionName, controllerName and AjaxOptions.


1 Answers

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. } 
like image 87
moribvndvs Avatar answered Sep 18 '22 16:09

moribvndvs