Kiyoshi
Kiyoshi

Reputation: 203

Can I customize @using Html.BeginForm() by giving it a class?

I looked through the different ways I can use

@using (Html.BeginForm()) 

but I am still very confused. What I would like to do is to supply this with a class name so I could set up my own parameters.

Also I would like to supply a class to these:

@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")
@Html.ValidationMessageFor(m => m.Login.UserName)

Is this possible?

Upvotes: 2

Views: 2792

Answers (2)

Neil Knight
Neil Knight

Reputation: 48537

Yes:

@Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "myClass" })

and

@Html.ValidationMessageFor(m => m.Login.UserName, "Validation message", new { @class = "myOtherClass" })

You can also do:

@Html.BeginForm(htmlAttributes: new { @class = "myClass" })

Upvotes: 9

Zruty
Zruty

Reputation: 8667

There are overloads that accept htmlAttributes parameter. Use it like this:

@Html.ValidationMessageFor(m => m.Login.UserName, "validation message", new { @class="custom-class" } )

Upvotes: 1

Related Questions