I found this article and I know its for webpages and not for MVC. My question or problem is the following. If a user provides the correct input for a textbox, I want to change its background-color to green, I did it with red for errors, that works. But the example shown in this article does not seem to work in my application and I did not find another example that made it work. So here is my CSS-Style that I tried to apply:
ErrorAndValidationHighlighting.css:
.input-validation-error {background-color: #ffb3b3;} .input-validation-valid {background-color: #6BEF66;}
The TextBoxes in my view all look like this:
@Html.TextBoxFor(m => m.AdditionalComment)
As I said above, it works for the errors like it should, background-color changes to red and is displayed, but for valid input it does not work at the moment, so maybe you guys see what mistake Im doing or what is missing to make this work. Thanks in advance.
.css
@Html.ValidationMessageFor()
where you'd like your validation errors - then MVC will do the rest. Also, in your ViewModel for what you're displaying you should set some attributes to complement the MVC validationValidationMessageFor()
helper as I suggested previously). If you could post a bit more code it would be useful. Here's a great tutorial on validation in MVC: asp.net/mvc/overview/older-versions/…class="input-validation-valid"
applied to inputs. Itsclass="valid"