asp.net mvc - how to set default value HTML.EditorFor() -


how can set default value im editorboxes in case dont write in box dont send null.

 <div class="editor-label">         @html.label("description")         </div>                                           // somthing        <div>@html.editorfor(model => model.description, " default value ")         @html.validationmessagefor(model => model.description)     </div> 

or if change to

 @html.textboxfor(model.somthing, "default value") 

to display default value in field must assign 'value' property in htmlattributes in example:

@html.editorfor(model => model.description,  new { htmlattributes = new { @class = "form-control", @value = viewbag.defaultdescription } }) 

make sure v in value uppercase.

this way assigning default value on html field , not in model.

assigning default values in model force create model object first , set default values non-nullable fields datetimes, make page show annoyings 1/1/1001 00:00:00 values in datetime fields have in rest of model.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -