c# - Set Datetimepicker date NaN -
i have datetimepicker , save date selected save button in sqlserver code. reason need have nullable datetime:
clienteadd.datalead = string.isnullorempty(form["datalead"]) ? (datetime?)null : datetime.parse(form["datalead"]);
the save function works fine, problem when set datetimepicker loaded. recover data sqlserver code:
var elemento = new{ datalead = clientelead.datalead }
i sent 'elemento' view jquery , set datetimepicker:
$('#datalead').datepicker('setdate', (new date(result.datalead)));
when set 'datalead' have nan date. know problem conversion of datetime don't know how save , after load data.
thanks all
from docs here, javascript's date object can recive either milliseconds
number or datestring
. guess result.datalead
object since datalead
object (a c# datetime). that's why can't assignment want.
the answer here explains how millis datetime
.
try following code (untested):
var elemento = new{ datalead = (long)clientelead.datalead.totalmilliseconds }
and regular assignment:
$('#datalead').datepicker('setdate', (new date(result.datalead)));
update:
since clientlead.datalead
can null have make sure won't nullpointerexception
when doing (long)clientelead.datalead.totalmilliseconds
, maybe consider checking typeof result.datalead != "undefined"
in javascript
Comments
Post a Comment