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:


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; }


<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 class="has-error">
        @Html.ValidationMessageFor(m => m.searchClientID, null, new { @class = "has-error" })


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

Related posts

Recent Viewed