asp.net mvc - Date format not maintained in jquery post -


in mvc 4 project developed in vs2010, have screen has dropdown shows date dd-mmm-yyyy display text, underlying value dd-mm-yyyy.

in function posts data, can see selected value in dd-mm-yyy when alert out.

  alert($("#dropdwn_birthdateval").val()); 

this line above shows date desired in dd-mm-yyyy format.

however in same method when try post value controller

  $.ajax({             type: "post",             url:"@url.content("~/home/getuserdetails")",             async:false,             datatype: "json",             data: {                  //.....other string , integer values                  //.....that go thru                 "mydto.dob":  $("#dropdwn_birthdateval").val()             },             error: function (error) {                 alert(error);             },             ..... remaining code here  

...the date comes in 1/1/0001 12:00:00 am

the controller action posting to, 'getuserdetails' has viewmodel class called uservm paramter. uservm has dto class called mydto. within mydto date property called dob of type datetime. mydto has other properties well. string , integer values go thru properly.

what missing?

you need format date iso-8601 when sending server, e.g. 2011-12-19t15:28:46.493z

this answer this similiar question shows number of way accomplish this, favorite json.parse(json.stringify(new date())) won't support ie7.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -