UnbindModel - RouteValueDictionary already contains key

Sep 5, 2012 at 7:39 PM

I am not a big fan of adding my route data as parameters to the ActionName method:

Example:  MVC.Home.Index(id1, id2, id3)

I would much rather use the AddRouteValues, as it seems more MVC-like:

MVC.Home.Index().AddRouteValues(new {id1 = Model.Id1, id2 = Model.Id2})

But this causes errors when the Index method does not have a parameterless overload.  So I changed the T4MVC.tt file to show this:

public class DefaultModelUnbinder : IModelUnbinder {
        public void UnbindModel(RouteValueDictionary routeValueDictionary, string routeName, object routeValue) {
            if (routeValueDictionary.ContainsKey(routeName)) {
   routeValueDictionary.Add(routeName, routeValue);

 Will this break anything that I am not seeing?  Or will this cause any issues I am not seeing?


Sep 5, 2012 at 8:31 PM

Yes, I think that's a good change. Or more simply just

routeValueDictionary[routeName] = routeValue;

Verify that it works for you and I can get that in. You can also send a pull request instead and I'll merge it in, but if that's too painful I can just make the change. :)

Sep 17, 2012 at 10:10 PM

Fixed in T4MVC 2.10.2.