Question

I have a model in MVC 4 that has a date field in it that is not required (NOTE: it is a nullable datetime field).

I can create an item with my view without a problem.

If I set the date field within the form and go back to edit it, I am unable to clear the date field because now all of a sudden the field has become required and I can't get passed validation.

Is there a way around this? I just want to blank out a previously entered date field.

Was it helpful?

Solution

Found the answer:

Needed to add to Global.asax.cs

protected void Application_Start()
{
    DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
   .....
}

see: Unrequired property keeps getting data-val-required attribute

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top