0

is there a way for me to override the message from Html.ValidationMessageFor. So when it is activated, it will display the new message ?

I have tried to add this to my model:

[Required(ErrorMessage = "validation error message goes here")]
public decimal Average { get; set; }

but that wont work.

and if i add the message to the html it self, it will display it always on page load:

@Html.ValidationMessageFor(x => x.Average, "validation error message goes here", new { @class = "text-danger" })

I need to change the error message provided for my language (danish) instead of just the model name which is in english.

2
  • Not clear what you asking, or why your saying [Required(ErrorMessage = "...")] does not work. But you can use resource files to localize your error messages - refer this blog for an example Commented Apr 13, 2017 at 2:23
  • i found the solution, i just removed "validation error message goes here" from html.validationmessagefor, and typed null instead. Then it didn't override the required validation message in my model. Commented Apr 18, 2017 at 6:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.