JSON Binding Support is only available in ASP.NET MVC 3. However, there is a workaround we can do to make this work in ASP.NET MVC 2.
I will use the same ViewModel in ASP.NET MVC 3 Post.
Here’s the Controller:
For simple demonstration purpose, the Controller only returns Json object pass to the Controller.
As mentioned in ASP.NET MVC 3 Post, I use Poster, a Mozilla Firefox add-on to test posting to the Controller.
Here’s the request:
Here’s the response:
Basically, this approach is the same as what I described here. We take string input (which essentially is a JSON string) in our Controller and deserialize it to our ViewModel object.
Few things to note:
- The request must NOT be “application/json”. The request is a regular post action request.
- Parameter used in Controller must match the request parameter’s name.