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
Post a Comment