data annotations - ASP.NET MVC Core date only format is not working using DataAnnotation -


following viewmodel used in view supposed display startdate as, 9/30/2015. displaying 9/30/2015 12:00:00 am. how can make display without time while using dataannotaion? know can use @model.startdate.tostring("mm/dd/yyy") inside view display date only. mean have in every view using following viewmodel:

viewmodel:

... [displayformat(dataformatstring = "{0:mm/dd/yyyy}")] public datetime startdate { get; set; } ... 

update

the corresponding model class of above viewmodel has following dataannotation correctly creates data type in sql server table date; , when run query on corresponding table in ssms correctly displays startdate column's data dates only, say, 9/30/2015 etc.)

model

... [datatype(datatype.date)] public datetime startdate { get; set; } ... 

startdate in sql db in fact date only. moreover, if run query on ssms correctly returns date only.

there 2 solutions problem. per comments, using @model.startdate display date.

you can either this:

@model.startdate.tostring("d") 

or, can use model based approach in viewmodel , this:

[datatype(datatype.date)] public datetime startdate {get;set;} 

then, in view use:

@html.displayfor(m => m.startdate) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -