Post arbitrary JSON data to a MVC controller action method

If you want to sent arbitrary JSON data to a MVC controller action method, you can use the following code:

[HttpPost]
public ActionResult HandleRequest()
{
// Read the RAW JSON from the request, 
// because MVC does not support a dynamic input parameter or an input parameter of type JObject.
// ASP .NET Web API does support a dynamic input parameter or an input parameter of type JObject.
string json = new StreamReader(this.Request.InputStream).ReadToEnd();
dynamic clientData = JObject.Parse(json);

Leave a Reply

Your email address will not be published. Required fields are marked *