views:

65

answers:

1

Wondering if there is a better way to do this with ASP.NET MVC2. The following Posts on SO are little dated:

http://stackoverflow.com/questions/267707/how-to-pass-complex-type-using-json-to-asp-net-mvc-controller

http://stackoverflow.com/questions/560575/asp-net-mvc-how-to-pass-json-object-from-view-to-controller-as-parameter

and also without using phil haack's futures library in the following post. http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx

Basically what I am doing right now is using the JavaScriptSerializer and deserializing in action/actionfilter.

A: 

Phil Haack's post is still up to date for MVC 2 - you need to register a JsonValueProviderFactory to deserialize an object from the posted JSON.

This is baked into MVC 3 already, so I would suggest downloading the MVC 3 preview and taking the JsonValueProviderFactory from the assembly

Russ Cam
I can't use MVC 3 preview for a production App. Also using MVC futures is not an option :(
sdon
I'm not suggesting using MVC3 in your app, just the JsonValueProviderFactory class from the assembly. or you could write your own instead :)
Russ Cam