0

I am doing an ajax Post with Model and everything works fine except one datetime property,I can see in network tab of browser following values are getting passed in request payload,but when I put debugger at server side action method,that datetime property showing null.

Value in Request Payload

DevelopmentPlan_CompletionDate:"/Date(1491796800000)/"

Model Property

 public DateTime? DevelopmentPlan_CompletionDate { get; set; }

It seems /Date(1491796800000)/ format is creating issue,I am reading DateTime Value from backend Sharepoint list and value is 4/18/2017 4:00:00 AM.Now At client side I am doing this

   var dataModel = @Html.Raw(Json.Encode(Model));
   sessionStorage.setItem('DataModel', JSON.stringify(dataModel));

After doing above,my datetime property changes to "/Date(1491796800000)/" and that is causing issue when doing ajax post with this value

F11
  • 3,703
  • 12
  • 49
  • 83
  • Show the relevant code including the ajax and how you set the property in your script - and refer [this question/answer](http://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format) –  Apr 11 '17 at 00:49
  • update some findings – F11 Apr 11 '17 at 01:10
  • Don't `JSON.stringify(..)` it - just `sessionStorage.setItem('DataModel', datamodel));` –  Apr 11 '17 at 01:12

1 Answers1

0

it is because Json.Encode() converts DateTime to this format /Date(1491796800000)/ you should use Newtonsoft to convert to Json like

var dataModel = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model))

this will convert DateTime to this format 2017-04-11T08:55:24.659262+05:00 which can be understandable by DateTime and hence it is converted to Json format so no need to use JSON.stringify to convert to Json

sessionStorage.setItem('DataModel', dataModel);
Usman
  • 4,615
  • 2
  • 17
  • 33