Search code examples
asp.net-mvc-4mvcroutehandler

RouteValueDictionary being passed by default in MVC4


I have encountered a problem while upgrading to MVC4 and I was wondering if anyone else has seen this problem and how to get around it. Whenever I put a IDictionary, Dictionary or RouteValueDictionary to the parameter list of an action, the route values for that MVC call are being passed.

To reproduce this problem create an MVC4 web project using the default Internet Application settings and add

IDictionary<string, object> myDictionary = null 

to the parameter list of the Index controller and put a breakpoint inside the method. You will see that the IDictionary parameter is populated by the model binder with the route values.

How do I turn this off, or get around this?


Solution

  • It looks like after looking through bug reports for MVC4 the following issue is being tracked with the Dictionary<> model binder.

    http://aspnetwebstack.codeplex.com/workitem/373

    The workaround seems to be to remove the Dictionary from the parameters list and do the following:

    [HttpPost]
    public void Index(FormCollection form)
    {
         var values = new Dictionary<string, object>();
         this.UpdateModel(values, "values");
    }
    

    Hopefully this helps someone else. Now if they would just fix it. Does anyone have a better work around?