Register a custom model binder in MVC 4

asp.net-mvc, asp.net-mvc-4, model-binding

Solution

You can register your model binder in the same way(in the Global.asax.cs) and you can also use the `System.Web.Mvc.IModelBinder` interface.

However, the System.Web.Http namespace is basically for the ASP.NET MVC Web API(i.e. for building web services).

Problem

In MVC 3, I created custom model binders by creating a new class that implemented `Systen.Web.Mvc.IModelBinder`, and then registered it inside `Global.asax.cs` and inside `Application_Start()` using `ModelBinders.Binders.Add(typeof(sometype), new MyModelBinder());` In MVC 4 I understand that you are supposed to use `System.Web.Http.ModelBinding.IModelBinder` to implement model binders. So I have two questions: Why are we supposed to use the model binder from `System.Web.Http.ModelBinding` instead of the one from `Systen.Web.Mvc`? I don't see it is listed as deprecated anywhere, so what is the problem with the old one? If I implement my model binder from the `System.Web.Http.ModelBinding.IModelBinder`, how do I register it inside my application so it will actually be used?

Original source