0
votes

when I'm using @Html.ValidationMessageFor helper on page for non-valid fields .Net generates error message in span-tag with standart class - "field-validation-error".

<span class="field-validation-error" data-valmsg-for="FirstName" data-valmsg-replace="true">The FirstName field is required.</span>

Can I set my custom class for it? I'm just trying to use Bootstrap 3 error alert classes. The FirstName field is required.

1
Just copy the css content of BT class "has-error" to the ASP "field-validation-error" class. - BENARD Patrick

1 Answers

0
votes

You can assign your own CSS class to be output for validation errors using

HtmlHelper.ValidationMessageCssClassName = "you class name here";

Note that you'll also need to modify jquery.validate.unobtrusive.js to use your class name if using jquery validate plugin on the client side.

Alternatively, you could copy the CSS rules from the class in question over to a .field-validation-error CSS class declaration.