3

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.

Community
  • 1
  • 1
Przemek
  • 53
  • 2
  • 7
  • Please elaborate and show some code which ain't working....Right now, it's impossible to understand what problems are you having – Pankaj Upadhyay Jan 21 '12 at 13:02

3 Answers3

1

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.")
        );
    }
1

Take a look at Model Metadata and Validation Localization using Conventions

Eranga
  • 32,181
  • 5
  • 97
  • 96
0

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.

Community
  • 1
  • 1
Stuart Dobson
  • 3,001
  • 4
  • 35
  • 37