How to display default values โ€‹โ€‹as empty rather than default?

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

By default, empty fields are required. How to do it?

I already found [DefaultValue("")] and found that this does not affect this problem.

Thanks!

ASP.NET MVC 4 RC

+6
source share
1 answer

Try declaring the properties of your ViewModel as nullable with ?

 public DateTime? DateValue { get; set; } public int? IntValue { get; set; } 
+16
source

Source: https://habr.com/ru/post/919164/


All Articles