I see examples all over the net of people setting up their custom model binders like this:
// global.asax
protected void Application_Start()
{
ModelBinders.Binders.Add(typeof(YourModel), new YourBinder());
}
But when I try that, it doesn't compile ( .Binders
isn't found). What gives?
It turns out this was just a naming conflict because I had put my custom model binder in a folder/namespace called "ModelBinders". You can fix this one of two ways:
CustomModelBinders
Use a fully qualified reference to the ModelBinders
like this:
System.Web.Mvc.ModelBinders.Binders.Add( /* ... */ );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.