c# - Specifying a DataType for a propertyinside a nested class? -
i'm making mvc5 website, , created viewmodel able access multiple models/classes in view. viewmodel contains classes generated entityframework. looks this:
public class personeelskaartvm { public personeel personeel { get; set; } public gebruikers gebruikers { get; set; } public list<sysgroep> lidvansysgroep { get; set; } public list<relsgrps> lidvanrelsgrps { get; set; } public personeel_uren urenperjaar { get; set; } public persoon_overw overwerkperjaar { get; set; } public cboalgemeen status { get; set; } public list<relafdeling> lidvanrelafdeling { get; set; } public list<persoon_vakgroep> lidvanpersoonvakgroep { get; set; } public list<vakgroep> lidvanvakgroep { get; set; } public list<competentieentiteit> lidvanpersooncompetentie { get; set; } public list<competenties> lidvancompetenties { get; set; } //volle lijsten: public list<cboalgemeen> alleburgstaten { get; set; } public list<overwerk> alleoverwerk { get; set; } public list<onreg_toeslag> alleort { get; set; } public list<cboalgemeen> allestatussen { get; set; } public list<cboalgemeen> allecontractvormen { get; set; } public list<functie> allefuncties { get; set; } }
traditionally used [datatype(datatype.date)]
datetimes need date. how can achieve property in personeel
? in personeel
property called gebd
, i'd set datatype personeel.gebd
.
the same property in personeel
called creditcard
used [datatype(datatype.creditcard)]
however cannot change auto-generated ef classes.
//edit: because couldn't explain myself well, ill try explain myself better.
in example if have model webpage:
public class exampleviewmodel{ public persoon person{get;set;} }
and persoon defined this:
public class persoon{ public datetime gebd {get;set;} }
and can't change persoon class.
the output in textfield in html be: 04-05-1985 00:00:00 if access exampleviewmodel.person.gebd
if add datatype markup ( [datatype(datatype.date)] ), output be: 04-05-1985. without time suffix.
but because viewmodel has nested models in it, how can apply datatype markup in viewmodel manipulate property in in class, inside viewmodel.
i hope explained better.
you can redefine/override auto generated model
public class examplemodelmetadata { [display(name = "birthday")] [displayformat(dataformatstring = "{0:dd/mm/yyyy}", applyformatineditmode = true)] public datetime birthday {get;set;} } [metadatatypeattribute(typeof(examplemodelmetadata))] public partial class examplemodel { }
this applied after refresh models database.
Comments
Post a Comment