KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've been searching for a while now and haven't found a solution yet. I'm an ASP.NET and MVC4/Razor2 newbie, so I'm mostly editing the default project. Anyway, my issue is that I'm using Twitter Bootstrap and I need to add an error CSS class on a div if the under-laying field is not valid. So far I have this: <div class="control-group error"> @Html.LabelFor(m => m.Password, new { @class = "control-label" }) <div class="controls"> @Html.PasswordFor(m => m.Password) @Html.ValidationMessageFor(m => m.Password, null, new { @class = "inline-help error" }) </div> </div> What should I do to make Razor insert the error class in the first div of my snippet when the field is invalid. UPDATE: I found a way to do it, but it doesn't feel right in comparison to the rest of the code. Is there a better way or is it the way to do it? <div class="control-group@((!ViewData.ModelState.IsValidField("Password")) ? " error" : "")">
Tags (comma-separated)
Save Edits
Cancel