I'm using Bootstrap with ASP.NET MVC and using @Html.TextboxFor<...>(...)
helper to create textboxes for my model.
My current code looks as below.
<div class="form-group">
@Html.LabelFor(m=>m.Email,"Email Address")
<div class="input-group">
@Html.TextBoxFor(m=> m.Email,
new { @class = "form-control", placeholder = "Enter e-mail" })
<span class="input-group-addon">@@mydomain.com</span>
</div>
<span>@Html.ValidationMessageFor(m=>m.Email) </span>
</div>
This works fine, though I want to add 'has-error'
css class to the top div (the one with class=form-group
). This is because I want to use the bootstrap classes when there's an error.
I understand that the HTML helper and validation adds 'input-validation-error'
class, but I want the bootstrap class instead, and instead of the input, I want it on the parent div, so the styling works as expected.
How can I accomplish this ?