Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display default values as blank instead of the type's default value?

Tags:

asp.net-mvc

I have a view model with a couple of properties that are not displaying as desired. One of the properties is of type datetime. The other is an int. In my Create view, the datetime appears with a default value of 1/1/0001 12:00:00 AM and the int has of default of 0.

We want empty fields by default. How do I do this?

I already found [DefaultValue("")] and found it does not address this issue.

Thanks!

ASP.NET MVC 4 RC

like image 642
user1469655 Avatar asked Jun 27 '12 17:06

user1469655


1 Answers

Try declaring the properties on your ViewModel as nullable using ?

public DateTime? DateValue { get; set; }
public int? IntValue { get; set; }
like image 149
Kevin Aenmey Avatar answered Oct 13 '22 12:10

Kevin Aenmey