How can I avoid generating the html attribute "data-val-date" for an element created from the Datetime property?
Model:
public class RegisterModel { [Required] [Display(Name = "Date of birth")] public DateTime? DateOfBirth { get; set; } }
View:
@Html.LabelFor(m => m.DateOfBirth) @Html.EditorFor(m => m.DateOfBirth)
In fact, I create three items with drop-down lists for selecting a date of birth that do not give values ββin a date format. Some of the solutions I saw were to work: removing validation using javascript. The solution I'm assuming is to split the DateTime property into three long ones for each value (day, month, year).
data-val-date is used by the validation system to check the date. If you delete it, client-side validation will not work.
, , .
, ... -, mvc4 , Data-val-date = "" - datetime viewmodel. , .
:
$.validator.addMethod('date', function (value, element) { return true; // since MVC4 data-val-date is put on EVERY vm date property. Default implementation does not allow for multiple cultures... });
"DateTime.cshtml" EditorFor, TextBoxFor, .
global.asax, .
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;