views:

160

answers:

2

I encounter an error of the form: "The model item passed into the dictionary is of type FooViewData but this dictionary requires a model item of type bar" even though I am passing in an object of the correct type (bar) for the typed user control.

+1  A: 

What has probably happened is that the object provided when rendering the user control is actually null.

Graphain
+3  A: 

What @Graphain said is probably the reason you're seeing this error.

If you want to know why; it is because when you pass null as the controlData parameter when using RenderUserControl(), the framework will try to pass the view data from the current view context onto the user control instead (see UserControlExtensions.DoRendering method in System.Web.Mvc).

Fredrik Kalseth
{"cc_re__cc_re__cc_by_sa_2_5": ["T Site Maps</a>\n            </div>\n          </div>\n        </div>\n      </div>\n    </div>\n    <div id=\"footer\">\n      <div class=\"wrapper\">\n        <div id=\"attribution\">The questions, topics and answers come from <a rel=\"nofollow\" target=\"_blank\" href=\"http://serverfault.com\">serverfault.com</a>, <a rel=\"nofollow\" target=\"_blank\" href=\"http://stackoverflow.com\">stackoverflow.com</a> and <a rel=\"nofollow\" target=\"_blank\" href=\"http://superuser.com\">superuser.com</a>, and are licensed under the <a rel=\"nofollow\" target=\"_blank\" href=\"http://creativecommons.org/licenses/by-sa/2.5/\">cc-wiki</a> license.</div>\n        <div id=\"copyright\">\u00a9 2010 <a href=\"http://chadscira.com/\">Chad Scira</a> / icodeforlove</div>\n      </div>\n    </div>\n    <script type=\"text/javascript\">var globals = {};globals['servertime'] = '1708656089';globals['cdn'] = 'http://ansaurus.com/';globals['basedomain'] = 'http://ansaurus.com/';globals['pagetype'] = 'question';</script>\n    <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\" type=\"text/javascript\"></script>\n    <scrip"], "copyright__copyright__copyright": ["What has probably happened is that the object provided when rendering the user control is actually null.\n\nGraphain\n+3\u00a0 A:\u00a0\n\nWhat @Graphain said is probably the reason you're seeing this error.\n\nIf you want to know why; it is because when you pass null as the controlData parameter when using RenderUserControl(), the framework will try to pass the view data from the current view context onto the user control instead (see UserControlExtensions.DoRendering method in System.Web.Mvc).\n\nFredrik Kalseth", "What has probably happened is that the object provided when rendering the user control is actually null.\n\nGraphain\n+3\u00a0 A:\u00a0\n\nWhat @Graphain said is probably the reason you're seeing this error.\n\nIf you want to know why; it is because when you pass null as the controlData parameter when using RenderUserControl(), the framework will try to pass the view data from the current view context onto the user control instead (see UserControlExtensions.DoRendering method in System.Web.Mvc).\n\nFredrik Kalseth", "What has probably happened is that the object provided when rendering the user control is actually null.\n\nGraphain\n+3\u00a0 A:\u00a0\n\nWhat @Graphain said is probably the reason you're seeing this error.\n\nIf you want to know why; it is because when you pass null as the controlData parameter when using RenderUserControl(), the framework will try to pass the view data from the current view context onto the user control instead (see UserControlExtensions.DoRendering method in System.Web.Mvc).\n\nFredrik Kalseth"]}