I have a modelbinder being added during Application_Start like this:
protected void Application_Start()
{
XmlConfigurator.Configure();
// Model Binding
ModelBinders.Binders.Add(typeof(SessionUser), new SessionUserModelBinder());
////////////////
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
I would like the Application_Start method to call a separate method to add my custom model binder to the list like:
namespace NewNameSpace
{
public class TestStartClass
{
public static void AppStart()
{
ModelBinders.Binders.Add(typeof(SessionUser), new SessionUserModelBinder());
}
}
}
The problem is that when I try this, Binder in ModelBinders.Binder returns an error which says:
Error 1 'System.Web.Mvc.ModelBinders' does not contain a definition for 'Binder'
I am using System.Web.Mvc. What am I missing that’s preventing this from working?
It looks like you must have a typo in your code. The error message is saying you are trying to reference a class member like
ModelBinders.Binder. You need that to beModelBinders.Binders.Add().ModelBinders.Binders Property MSDN Reference