jgauffin / griffin.mvccontrib

A contribution project for ASP.NET MVC3
http://blog.gauffin.org/tag/griffin-mvccontrib/
GNU Lesser General Public License v3.0
83 stars 40 forks source link

Validation doesn't work when setting ErrorMessage parameter #5

Closed Edddy closed 12 years ago

Edddy commented 12 years ago

If you try to override the default error message the validation is skipped and always validate i.e:

public class Product {

    [Required]
    public String Name { get; set; }

    // this wont work
    [Required(ErrorMessage = "Other is required")]
    public String Other { get; set; }

}

Results

Edddy commented 12 years ago

Was this fixed or it's a "Won't fix"?

Edddy commented 12 years ago

@jgauffin: It's hard to be collaborative if you don't communicate with us

jgauffin commented 12 years ago

I'm on vacation. Will look at is as soon as I get back. I thought that I had fixed it. However it's hard to get everything working properly (1. be able to use custom validation attributes 2. use the built in attributes 3. use custom error messages in the attributes).

Microsoft hides the actual language handling inside the dataannotation attributes and then caches them in MVC3.

Edddy commented 12 years ago

I understand it's hard and I can try to help you in anything you need, but we need that you coordinate the efforts. Anything from "Too hard, won't fix", "Please try to fix it yourself", or "Fixed" is good for me.

Hope you enjoy your vacations!

jgauffin commented 12 years ago

Should work now

Edddy commented 12 years ago

Excellent!

How to we instanciate the providers now? This old sample code does not work now

        var stringProvider = new ResourceStringProvider(Resources.LocalizedStrings.ResourceManager);
        ModelMetadataProviders.Current = new LocalizedModelMetadataProvider(stringProvider);
        ModelValidatorProviders.Providers.Clear();
        ModelValidatorProviders.Providers.Add(new LocalizedModelValidatorProvider(stringProvider));
jgauffin commented 12 years ago

humm. That should work. What kind of error do you get? (although I never tried with a string table only)

(you can email me at jonas.gauffin@gmail.com for faster responses regarding this issue)