user8103 user8103 - 1 month ago 7
ASP.NET (C#) Question

Mvc add id and css class in MVC Html.BeginForm()

I am new to MVC.

How I can add id and css class in MVC Html.BeginForm().

This is html form.

<form id="frmId" class="frmStyle">
...
</form>


I tried this but got error.

@Html.BeginForm("actionName", "controllerName", new {id="frmId", class = "frmStyle"})

Answer

We add as part of htmlAttributes.

@Html.BeginForm("actionName", "controllerName", FormMethod.Post,
 new {id="frmId", @class = "frmStyle"})