2

Im developed the MVC project , I want to style this display error message but its not working,i cant add this for CSS style ,How can i do it?

@Html.ValidationMessageFor(a => a.SelectedValue)   

CSS

.field-validation-error {
    color: #ff0000;
    position: absolute;
    left: 200px;
    top: 5px;  font-size:14px; font-family:'Arno Pro';
    width: 250px; /*background:url(../img/wrng_icn.png) no-repeat right center;
}
3
  • can you show rendered html from your ValidationMessageFor? Commented Oct 14, 2015 at 9:25
  • Did you add jquery-validation.css properly? Commented Oct 14, 2015 at 9:26
  • yeah im added <script type="text/javascript" src="~/Scripts/jquery-1.10.2.js"></script> <script type="text/javascript" src="~/Scripts/jquery.validate.min.js"></script> <script type="text/javascript" src="~/Scripts/jquery.validate.unobtrusive.js"></script> Commented Oct 14, 2015 at 9:29

1 Answer 1

4

You can assign custom attributes to Html Helpers like the below.

@Html.ValidationMessageFor(a => a.SelectedValue, new {@class = "field-validation-error"}); 

Update: Pass it a null to use a different overload

@Html.ValidationMessageFor(a => a.SelectedValue, null, new {@class = "field-validation-error"}); 
Sign up to request clarification or add additional context in comments.

9 Comments

@DavidG Please explain why? The answer is correct, it has fixed the OP's issue, isn't that the point of accepting an answer. Some newer users do not understand the concept of accepting answers. Otherwise this question will look unanswered. I never asked for upvotes.
omg its not working correctly, having erros, cant add for your solution,
@AlberttheCoder Why is it not working, just a minute ago you said thanks for the help its working what has changed?
not complied thid code, @Html.ValidationMessageFor(a => a.SelectedValue, new {@class = "field-validation-error"}); its not working sir
@JamieR Because it looks like begging. Let the answer stand for itself and the OP can decide if he/she wants to accept. On the subject of educating new users, it's sometimes OK to say things like "don't forget to accept/upvote any answers or questions that you find useful on Stackoverflow" but generally it's bad. See this link
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.