I'm trying to style my @HTML.ValidationMessageFor element with Bootstrap 3 but no CSS is applied. When consulting Bootstrap's documentation, it states:

To use, add .has-warning, .has-error, or .has-success to the parent element. Any .control-label, .form-control, and .help-block within that element will receive the validation styles.

Even after nesting the desired @Html.ValidationMessageFor as stated above, no styling is applied:

ValidationMessageForError

Please see my code snippets below:

Model Property:

[Range(0, int.MaxValue, ErrorMessage = "Client ID cannot be larger than 2147483647.")]
[RegularExpression(@"^[0-9]+$", ErrorMessage = "Client ID must be a positive number.")]
public int searchClientID { get; set; }

View:

<div class="form-group col-sm-4">
    <div class="input-group">
        <span class="input-group-addon" id="client-ID">Client ID</span>
        @Html.TextBoxFor(m => m.searchClientID, new { @class = "form-control" })
    </div>
    <div class="has-error">
        @Html.ValidationMessageFor(m => m.searchClientID, null, new { @class = "has-error" })
    </div>
</div>

EDIT WITH ANSWER:

<div class="has-error">
    @Html.ValidationMessageFor(m => m.searchClientName, String.Empty, new { @class = "help-block" })
</div>

Related posts

Recent Viewed