0

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.

8
  • @StephenMuecke Edit: Please post the code of what you did :)
    – Max
    CommentedOct 20, 2016 at 8:32
  • 1
    @M.Arendsen - OP has posted the code - its the .css
    – user3559349
    CommentedOct 20, 2016 at 8:33
  • I think you need to be using a @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 validationCommentedOct 20, 2016 at 8:33
  • It's a bit unclear what other HTML you're using (and if you've using the ValidationMessageFor() 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/…CommentedOct 20, 2016 at 8:37
  • 2
    Their is no class="input-validation-valid" applied to inputs. Its class="valid"
    – user3559349
    CommentedOct 20, 2016 at 8:44

1 Answer 1

0

Please apply this code and check the result

@Html.TextBoxFor(m => m.AdditionalComment,new {@class="input-validation-valid"}) 
2
  • Hi, I tried your example and it works. Now Im a bit confused, since @Stephen Muecke said above that there is no such class as input-validation-valid.
    – RawMVC
    CommentedOct 20, 2016 at 10:44
  • Edit: I have to correct myself at this point, the solution of you does not work was intended, because if validation fails, the background-color stays green instead of changing to red. So @Stephen Muecke was right, its just valid and it works with that.
    – RawMVC
    CommentedOct 20, 2016 at 10:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.