ASP.NET MVC 4 avoids generating data-val-date for date and time

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).

+5
source share
3 answers

data-val-date is used by the validation system to check the date. If you delete it, client-side validation will not work.

, , .

0

, ... -, 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, .

+12

global.asax, .

DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
0

All Articles