I am using the JsonValueProviderFactory in an MVC2 web app to handle JSON requests inbound from an iOS iPad app.
I don’t want to map my JSON to a type. I just want to receive the raw JSON and pass it on to a model for processing. What signature should my controller action have to allow me to access the raw JSON being passed to my controller?
Here are the three I’ve tried so far; none of them work:
[ValidateInput(false)] // Allow dodgy chars in the JSON e.g. "<aa>"
[HttpPost]
//public ActionResult PushObject(FormCollection form) // no joy
//public ActionResult PushObject(List<string> parms) // no joy
//public ActionResult PushObject(string jsonRequest) // no joy
{...
Why are you using a
JsonValueProviderFactoryif you want to get the RAW JSON. The whole point of this factory is to map it to a view model (which by the way is the correct way). If you want to get the Raw stuff you could always read theRequest.InputStreambut that would be absolutely horrible:you could at least hide this crap in a model binder:
and then have a controller action:
But of course the correct way to do this is to use a view model that will reflect the JSON structure that your iPhone will send: