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; }
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>
dont replace form-group with has-error.I have used something similar to this recently and try the following markup.
<div class="form-group has-error">
<div >
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
</div>
@Html.LabelFor(m => m.ConfirmPassword, new { @class = "control-label" })
@Html.ValidationMessageFor(m => m.ConfirmPassword, "", new { @class = "help-block" })
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With