简体   繁体   English

ModelBinders在Owin startup.cs中注册

[英]ModelBinders registration in Owin startup.cs

I've created a custom model binder for decimals but stuck with a problem. 我已经为小数创建了一个自定义模型绑定器但是遇到了问题。 I can't register it via Global.asax.cs because I don't have one. 我无法通过Global.asax.cs注册它,因为我没有。

How to make this line work in startup.cs class? 如何使这行在startup.cs类中工作?

ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder());

It will work in an OWIN startup class just fine provided System.Web.Mvc is referenced. 它将在OWIN启动类中工作,只需提供System.Web.Mvc

public void Configuration(IAppBuilder app)
{
    ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder());
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM