ASP.NET Web API - ModelBinders

前端 未结 4 385
渐次进展
渐次进展 2021-01-08 01:13

I need to use a custom modelbinder of some kind to always treat incoming dates in UK format, i have setup a custom model binder and registered like so:

Globa         


        
4条回答
  •  被撕碎了的回忆
    2021-01-08 01:56

    Attribute routing seems to conflict with model binding. If you use attribute routing, you can wrap the global.asax configuration into a single GlobalConfiguration.Config call to avoid the initialisation issues:

    GlobalConfiguration.Configure(config =>
    {
        config.BindParameter(typeof(DateTime), new DateTimeModelBinder());
        config.MapHttpAttributeRoutes();
    }
    

    (This might be fixed in the upcoming ASP.NET 5 if it's related to bug #1165.)

提交回复
热议问题