Monday, April 25, 2011

Registering ModelBinders

I have just updated to RC1 MVC from the beta product.

I have the following code in my Application_start (in the global.ascx)

System.Web.Mvc.ModelBinders.Binders[typeof(Shared.DO.Gig)] = new GigModelBinder();

This results in the following exception....

Method not found: 'System.Collections.Generic.IDictionary`2 System.Web.Mvc.ModelBinders.get_Binders()'.

From stackoverflow
  • Have you re-built your project. Binders is a ModelBinderDictionary, its not a IDictionary, quite possibly it was before RC1.

    ListenToRick : Yeah - I rebuilt. How are we supposed to register the Binders now?
    AnthonyWJones : The code looks ok to me assuming GigModelBinder implements IModelBinder. The error you were getting indicated an older definition of ModelBinders was being used.
    ListenToRick : Do you nean that my ModelBinders themselves (i.e. GigModelBinder) is out of date? They are in the format defined in the beta version of MVC?
    AnthonyWJones : I don't know what you GigModelBinder does or how its built so I can't tell whether its out-of-date. All I do know at this point is the definition of ModelBinders property has changed. If your binder implements IModelBinder that line of code should work.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.