In my MVC 4 project developed in VS2010, I have a screen that has a dropdown that shows date as dd-MMM-yyyy for the display text, with the underlying value as dd-mm-yyyy.
In the function that posts the data, I can see that the selected value is in dd-mm-yyy when I alert it out.
alert($("#dropdwn_BirthDateVal").val());
This line above shows my date as desired in dd-mm-yyyy format.
However in the same method when I try to post that value to my controller
$.ajax({
type: "POST",
url:"@Url.Content("~/Home/GetUserDetails")",
async:false,
dataType: "JSON",
data: {
//.....other string and integer values
//.....that go thru properly
"myDto.DOB": $("#dropdwn_BirthDateVal").val()
},
error: function (error) {
alert(error);
},
..... remaining code here
...the date comes in as 1/1/0001 12:00:00 AM
The controller action I am posting to, 'GetUserDetails' has a ViewModel class called UserVM as its paramter. UserVM has a dto class called MyDto. Within MyDto is a Date property called DOB of type DateTime. MyDto has other properties as well. The string and integer values go thru properly.
What am I missing?