ASP.NET MVC Json.Encode() DateTime encoding issue string not date type

This behavior is by design.

JSON (unlike Javascript) doesn't have a date type.


Date type has no literals in JavaScript. You will have to call its constructor.

var myDate = new Date(@Html.Raw(Json.Encode(Model.MyDateTime)));

Drawing inspiration from these answers, I needed to pass my nullable date to an MVC controller and have it model bound correctly. This is where i landed:

  var dob = @Html.Raw(Json.Encode(Model.BirthDate.HasValue ? Model.BirthDate.Value.ToShortDateString() : null));