我使用的是最近发布的MVC 4 Beta版(4.0.20126.16343)和我努力让围绕一个已知的问题与反序列化/模型绑定无法与阵列(见Stack Overflow here)把我的定制模型绑定到我的POST控制器
工作我很难让我明确的自定义绑定挂钩。我已经注册了一个客户IModelBinder(或试图),但是当我的后处理操作被称为我的自定义绑定没有命中,我只是得到默认序列化(与空数组 - 即使wireshark显示我传入的复杂对象包含数组元素)。
我觉得我错过了一些东西,并会非常感谢任何解决方案或见解。
谢谢。
从的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();
}
,我的定制绑定:
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;
}
和我的控制器就是:
public void Post(DocuSignEnvelopeInformation envelope)
{
Debug.WriteLine(envelope);
}
我打算继续,并将自己的答案标记为已接受 - 因为这是我所做的工作。如果您的相关事情发生,请随时添加任何内容。 – reuben