asp.net mvc - Using constant for defining property format in MVC -


in mvc application have many properties of datetime datatype , define dataformatstring on every new property in datatype defined below:

model:

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

instead of this, think there option define these dataformatstrings 1 place , @ once creating new class containing constant value or using web config, etc. so, in case best way use constant values i.e. date format, etc. use globalization string on web.config, not sure defining date dataformatstrings in web.config well. appreciated.

i'd opt custom attribute

public class shortdateformatattribute : displayformatattribute {     public shortdateformatattribute()     {         dateformat = "{0:dd/mm/yyyy}";         applyformatineditmode = true;     } } .... [shortdateformat] public datetime startdate { get; set; } [shortdateformat] public datetime enddate { get; set; } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -