最近リリースされたMVC4Beta(4.0.20126.16343)を使用しており、アレイで機能しない逆シリアル化/モデルバインディングに関する既知の問題の回避に取り組んでいます(ここでスタックオーバーフローを参照)
明示的なカスタムバインディングを接続するのに問題があります。カスタムIModelBinderを登録しました(または登録しようとしました)が、postアクションが呼び出されても、カスタムバインダーはヒットせず、デフォルトのシリアル化を取得します(null配列を使用-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);
}