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