asp.net mvc 4 - Nullable DateTime in Html Helper? -


i have asp.net mvc application trying add field edit date. date nullable datetime object. trying create 3 input boxes (month, day, , year) , have them linked model. want display date components in boxes when there date set. when there's not, should not have value , display placeholder.

enter image description here

i'm using html helpers (though not requirement), cannot work when date null.

here's have currently:

@html.editorfor(model => model.active_date_start.value.month, new { htmlattributes = new { @class = "form-control active-date", @placeholder = "mm", @maxlength = "2" } }) / @html.editorfor(model => model.active_date_start.value.day, new { htmlattributes = new { @class = "form-control active-date", @placeholder = "dd", @maxlength = "2" } }) / @html.editorfor(model => model.active_date_start.value.year, new { htmlattributes = new { @class = "form-control active-date", @placeholder = "yyyy", @maxlength = "4" } }) 

this works when date not null, causes error when is.

the other approach tried use pure html create these input boxes, , assemble date myself on backend when form submitted. couldn't work because couldn't figure out how conditionally set value of inputs.

any suggestions on how appreciated. thanks!


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -