views:

1137

answers:

4

Hello, 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.

+2  A: 

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".
Max Toro
Thank you for your answer, but for some reason it doesn't work.Maybe there is a different way to do it on mvc 2.
Godfa
You can find out using Reflector.
Max Toro
A: 

I can't get InvalidPropertyValue to work.

Here's the html:

        <p>
            <label for="Price">Price:</label>
            <%= Html.TextBox("Price") %>
            <%= Html.ValidationMessage("Price", "*") %>
        </p>

Here's the code in the Global.asax:

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);

        DefaultModelBinder.ResourceClassKey = "MyResources";
        ValidationExtensions.ResourceClassKey = "MyResources";
    }

In MyResources.resx I enter "Invalid value" for InvalidPropertyValue.

However, when I run the program and enter hjhjhjhjh for Price, it still comes up with the asterisk (*) instead of the message.

I am trying to follow the book (ASP.NET MVC Unleashed) but for some reason it's not working for me.

I am using MVC 1, Visual Studio 2008 Standard Version.

Any ideas???

Cynthia
+3  A: 

Got It.

In ASP.NET MVC 2 RC, It is PropertyValueInvalid, not InvalidPropertyValue.

C.T.
Thank you , works great!!!!
Godfa
+1  A: 

Try using: <%= Html.ValidationMessage("Price") %> without the star "*".

AH