Originally Posted by
Daniil
I am afraid we can't get it working as you need, because we don't have a good way to intervene the process of deserializing of an action's parameters. Please correct me if I am wrong.
My colleague, Vladimir, corrected me.
Please take a look at the following example.
http://mvc.ext.net/#/DataView_Basic/Overview/
There is the following action.
public ActionResult SubmitSelectionWithValues([ModelBinder(typeof(JsonModelBinder))]Dictionary<string, string>[] images)
A ModelBinder attribute is used to affect the deserialization process.
JsonModelBinder
public class JsonModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var vpr = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
if (vpr == null || vpr.AttemptedValue.IsEmpty())
{
return null;
}
return JSON.Deserialize(vpr.AttemptedValue, bindingContext.ModelType);
}
}
So, if you need custom deserialization, you should implement a binder like the JsonModelBinder one and pass it to a ModelBinder attribute.
Also it is possible to set a [ModelBinder] attributed for a class.
[ModelBinder(...)]
class ProductModel
{
...
}
Another approach is associating a type and a binder in Global.asax.
Hope this helps.