Przemek
Przemek

Reputation: 53

How to change default validation error message in ASP.NET MVC3?

I have common issue to that How to change default validation error message in ASP.NET MVC?

I'm trying to set default validation message for all types in app but I use MVC3 and Razor engine. Unfortunately ssg solution doesn't work for me.

Upvotes: 3

Views: 3521

Answers (3)

Ben Kauffman
Ben Kauffman

Reputation: 19

I know this is an old post but..

I just create C# validation code to determine if it isn't valid then return a validation message for an invalid string length.

    if (String.IsNullOrEmpty(ValidEIN))
    {
        Validation.Add("EIN",
        Validator.StringLength(0, 0, "Employee ID doesn't exist.")
        );
    }

Upvotes: 1

stuartdotnet
stuartdotnet

Reputation: 3034

This appears to be a problem in MVC3. http://forums.asp.net/t/1512140.aspx/1/10

Here are 2 possible workarounds.

1) Write a custom validation attribute with your own error message.

2) Do it client-side. Create a custom ClientDataTypeModelValidatorProvider, how to do this with MVC2 is explained here, I haven't tried it for MVC3. There is also some good info here.

Upvotes: 0

Related Questions