1

I've been "messing" around with the client side validation with ASP.NET MVC.

But the default messages are getting to me, I can't seem to overwrite some of them.

The only way I have found is to create resources in App_GlobalResources, like How to change default validation error message in ASP.NET MVC?

However, the required string name doesn't seem to work, has it changed since MVC 2?

I've been trying to keep it as Embedded Resources, but ended up coming short with the Enums, as it checks if it's valid automatically, but the string isn't localized. So I might as well just use the Global_AppResources.

Global.asax

        DefaultModelBinder.ResourceClassKey = "Global";
        ClientDataTypeModelValidatorProvider.ResourceClassKey = "Global";

Part of model:

    [Display(Name = "TimeDisplay", ResourceType = typeof(Resources.Models.Log))]
    [Required]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy HH:mm}")]
    [RegularExpression(@"\d{1,2}/\d{1,2}/\d{4} \d{1,2}:\d{1,2}")]
    public DateTime Time { get; set; }

App_GlobalResources folder with Global.resx

PropertyValueRequired   Weeee
Community
  • 1
  • 1
Zaixu
  • 191
  • 1
  • 2
  • 8

0 Answers0