When converts ASP.NET ValueProvider values?

My project is using ASP.NET MVC.

I am sending some data via ajax to a controller action which looks like

{ "data" : { "DATE" : "\/Date(1409097600000)\/", "NAME" : "thomas } }

      

I am using the ValueProvider of the controller to process the data:

var provider = ControllerContext.Controller.ValueProvider;
var value = provider.GetValue("data.DATE");
// value is now already "27.08.2014 00:00:00" 

      

Why?

Where does this part of the transformation take place?

Similar question: -

The above data is content type "application/json; charset=utf=8"

Having data as "application/x-www-form-urlencoded; charset=utf=8"

ASP.NET cannot convert date values.

 _model.DATE=%5C%2FDate(1409097600000)%5C%2F&_model.NAME=thomas

      

I think I did something wrong regarding \

and /

in the .NET-date format:\/Date(1409097600000)\/

(I know netwonsoft.json might be an alternative for javascript serialization, but unfortunately not at the moment)

+3


source to share


1 answer


If you are sending JSON data to the server using an Ajax message, then the content type header must reflect this fact (Content-Type = "application / json; charset = utf = 8") so that the server interprets the data correctly.

Content-Type = "application / x-www-form-urlencoded; charset = utf = 8", intended for sending data through an HTML form. If you are sending JSON data with this content type header, the browser will url encode it and generate the string you illustrated:



_model.DATE=%5C%2FDate(1409097600000)%5C%2F&_model.NAME=thomas

      

The Date () function doesn't make sense in an HTTP form post (it's a JSON function), so no date conversion is done.

0


source







All Articles