In my view I have the following:
@Html.TextBoxFor(model => model.EndDate)
When the code and the model is created I see it sets a default date rather than null for the field that's defined as follows:
public DateTime EndDate { get; set; }
In my view I see the following:
{1/1/0001 12:00:00 AM}
Is there some way that I can make it show/return an empty string if the field is not yet set to a value by my code. Here it just defaults to the above when I create a view and don't set that field.
Make EndDate nullable:
public DateTime? EndDate { get; set; }
DateTime is a value type which cannot have no value.
You have to use nullable of DateTime written like
public DateTime? EndDate { get; set; }
Now you can assign the null
value to your model in the controller:
return View(null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With