data-annotations

Disable Required validation attribute under certain circumstances

元气小坏坏 提交于 2019-11-26 03:08:35
问题 I was wondering if it is possible to disable the Required validation attribute in certain controller actions. I am wondering this because on one of my edit forms I do not require the user to enter values for fields that they have already specified previously. However I then implement logic that when they enter a value it uses some special logic to update the model, such as hashing a value etc. Any sugestions on how to get around this problem? EDIT: And yes client validation is a problem here

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

不打扰是莪最后的温柔 提交于 2019-11-26 00:59:50
问题 Say I have this property in my model: [DisplayName(\"test\")] [Required(ErrorMessage = \"required\")] public DateTime? SomeDate { get; set; } when you type in \"asdf\" in Html.TextBoxFor(model => model.SomeDate) , you get the validation error message \"The value \'asdf\' is not valid for test.\". How do you modify that message? ASP.NET MVC ignored [DataType(DataType.DateTime, ErrorMessage = \'some other message\')] 回答1: Apparently my question was already answered at How to replace the default

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

时间秒杀一切 提交于 2019-11-25 22:10:17
Say I have this property in my model: [DisplayName("test")] [Required(ErrorMessage = "required")] public DateTime? SomeDate { get; set; } when you type in "asdf" in Html.TextBoxFor(model => model.SomeDate) , you get the validation error message "The value 'asdf' is not valid for test.". How do you modify that message? ASP.NET MVC ignored [DataType(DataType.DateTime, ErrorMessage = 'some other message')] Sedat Kapanoglu Apparently my question was already answered at How to replace the default ModelState error message in Asp.net MVC 2? . I'll summarize it here: Create App_GlobalResources folder