user1469655
user1469655

Reputation: 1091

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

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

Upvotes: 7

Views: 7881

Answers (1)

Kevin Aenmey
Kevin Aenmey

Reputation: 13419

Try declaring the properties on your ViewModel as nullable using ?

public DateTime? DateValue { get; set; }
public int? IntValue { get; set; }

Upvotes: 17

Related Questions