I am using the recently released MVC 4 Beta (4.0.20126.16343) and am working on getting around a known problem with deserialization/model binding not working with arrays (see Stack Overflow here)
I am having difficulty getting my explicit custom binding to hook up. I have registered a custome IModelBinder (or attempted to) but when my post action is called my custom binder isn't hit and I just get the default serialization (with the null arrays - even though wireshark shows me the incoming complex object contains array elements).
I feel like I am missing something and would greatly appreciate any solution or insight.
Thanks.
from global.asax.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
protected void Application_Start()
{
ModelBinders.Binders.Add(typeof(DocuSignEnvelopeInformation), new DocusignModelBinder());
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();
}
and my custom binder:
public object BindModel(ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue("envelope");
var model = new DocuSignEnvelopeInformation();
//build out the complex type here
return model;
}
and my controller is just:
public void Post(DocuSignEnvelopeInformation envelope)
{
Debug.WriteLine(envelope);
}