by Syska
29. March 2010 00:11
Today I was making some refactoring to my site made in ASP.NET MVC 2. Created a complex class on my model, which should be passed to a RenderPartial like this:
<% Html.RenderPartial(“name”, Model.ComplexClass) %>
Corrected the type in the partial view I was expecting but got an odd error I think …
The model item passed into the dictionary is of type 'Model.MyModel', but this dictionary requires a model item of type 'Model.ComplexClass'.
So I started to look around, but got even more confused … recompiled, open and closed Visual Studio 2008, until I found the error. The reference to the ComplexClass was null. I’m not sure why it thinks it got a type of the model instead of the my ComplexClass.
This got to be a bug or something to do with the Reflection methods used to determine the type of the class passed to the PartialRender when trying to cast it and that failed. So when throwing the Exception, the information could be wrong … only guesses.
Update:
Searched the internet, and one person suggested parsing the values to the "ViewDateDictionary" ... but still not a good workaround here.