How to use the @Html.ValidationMessageFor to change the class of the text box

3

I bought a bootstrap template, the validation of the controls is done by a class that leaves the controls red. This would be the form-group has-error classes

Except that I've never used it that way, I'm used to using the code it generated itself: Example:

@Html.EditorFor(model => model.Campo, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Campo, "", new { @class = "text-danger" })

And then the validator writes the error message if the object returns with an error.

In control I use the default if (ModelState.IsValid)

How can I do to transform the class? If you can not use ValidationMessageFor , how could I do it?

UPDATE:

I want to change the textbox class and not display a message.

    
asked by anonymous 21.10.2015 / 02:52

1 answer

1

You can just add the class to your @html.ValidationMessageFor() , thus:

@Html.EditorFor(model => model.Campo, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Campo, "", new { @class = "form-group has-error" })

Look at this example in .NET Fiddle.

In it I'm adding the class error to my validation, leaving the source with 25px using this class:

.error{
    font-size: 25px;
}
    
21.10.2015 / 13:04