How to replace the default ModelState error message in Asp.net MVC 2?

Godfa picture Godfa · Oct 8, 2009 · Viewed 23k times · Source

I need to replace the model state resource (to another language).

I've seen some answers to the question above, but unfortunately I could'nt make it work. Any detailed answer or example would be appriciated.

Thank you.

Answer

Max Toro picture Max Toro · Oct 9, 2009

I don't know about v2, but this works on v1:

  1. Add a resource file in App_GlobalResources.
  2. In the resource file you can define strings named PropertyValueInvalid and PropertyValueRequired.
  3. On the Application_Start global.asax event set System.Web.Mvc.DefaultModelBinder.ResourceClassKey = "resource file name".