asp.net mvc - Set 'editor-field' value in ASP MVC3 View -



asp.net mvc - Set 'editor-field' value in ASP MVC3 View -

i give field in asp mvc view default value of current date, cannot figure out how in view code. need allow field update-able, however, since not current date. suggestions?

<div class="m-editor-label"> effective date </div> <div class="m-editor-field"> @html.editorfor(model => model.effectivedate) @html.validationmessagefor(model => model.effectivedate) </div>

edit

i have tried give field default value in model

private datetime? effectivedate = datetime.now; public nullable<system.datetime> effectivedate { { homecoming datetime.now; } set { effectivedate = value; } }

however get property gives me next error message:

monet.models.agenttransmission.effectivedate.get must declare body because not marked abstract extern or partial

^ (monet name of project, , agenttransmission name of current model working in, of effectivedate property.)

second edit

per suggestion in 1 of answers below set constructor such, still set blank value in field when view rendered.

public agenttransmission() { effectivedate = datetime.now; }

third edit

fixed above issue get, posting entirety of have in controller far.

public agenttransmission() { effectivedate = datetime.today; this.agencystat1 = new hashset<agencystat>(); } //have tried without , got same results private datetime? effectivedate = datetime.today; public nullable<system.datetime> effectivedate { { homecoming effectivedate; } set { effectivedate = value; } }

i set default value in constructor model class. this:

class yourclass { public datetime effectivedate {get;set;} public yourclass() { effectivedate = datetime.today; } }

asp.net-mvc asp.net-mvc-3

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -