Skip to content

ModelBinders registration

hazzik edited this page Apr 14, 2012 · 2 revisions

The MvcExtensions provedes a way to register custom model binders. All you need to do is to inherit from ConfigureModelBindersBase class:

public class ConfigureModelBinders : ConfigureModelBindersBase
{
    public ConfigureModelBinders(TypeMappingRegistry<object, IModelBinder> registry) : base(registry) { }

    protected override void Configure()
    {
        Registry.Register<ProductEditModel, ProductEditModelBinder>();
    }
} 

And then include that task into bootstrapper:

//Global.asax.cs
public class MvcApplication : MvcExtensions.WindsorMvcApplication
{
    public MvcApplication()
    {
        Bootstrapper.BootstrapperTasks
            // other tasks here
            .Include<ConfigureModelBinders>();
    }
}
Clone this wiki locally