Adding CSS class to Html.BeginForm()

.NetCssFormsasp.net Mvc-4Html Helper

.Net Problem Overview


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" })) 
{
}

.Net Solutions


Solution 1 - .Net

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

Solution 2 - .Net

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

Solution 3 - .Net

Or simply using html :

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

</form>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVishalView Question on Stackoverflow
Solution 1 - .NetmoribvndvsView Answer on Stackoverflow
Solution 2 - .Netp4rdsView Answer on Stackoverflow
Solution 3 - .NetFrédéricView Answer on Stackoverflow