Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mdarnall/855923 to your computer and use it in GitHub Desktop.
Save mdarnall/855923 to your computer and use it in GitHub Desktop.
using System;
using System.Web.Mvc;
namespace NewInMVC3.ModelBinder
{
public class GenericModelBinderProvider : IModelBinderProvider
{
public IModelBinder GetBinder(Type modelType)
{
var genericType = typeof (IModelBinder<>).MakeGenericType(modelType);
return (IModelBinder) DependencyResolver.Current.GetService(genericType);
}
}
}
using System.Web.Mvc;
namespace NewInMVC3.ModelBinder
{
public interface IModelBinder<T> : IModelBinder where T : class {}
}
using System.Web.Mvc;
using NewInMVC3.Models;
namespace NewInMVC3.ModelBinder
{
public class PersonModelBinder : IModelBinder<Person>
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
return new Person();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment