views:

1341

answers:

4

The strongly typed SearchViewData has a field called Colors that in it's turn is a ColorViewData. In my /Colors.mvc/search I populate this viewData.Model.Colors based on the given search criteria. Then, based on several factors, I render one of a set of user controls that are able to render itself with a ColorViewData.
So I will end up with

<%Html.RenderPartial("~/Views/Color/_ColorList.ascx", ViewData.Model.Colors);%>

This used to work just fine, but since the upgrade to the beta1, my user control always ends up with viewdata = null;

Suggestions?

A: 

Noticed the same thing, I fixed it with the following, though I'm not sure if it's the "right" solution:

<% Html.RenderPartial("xxx", new ViewDataDictionary(ViewData.Model.Colors)); %>
Karl Seguin
"xxx"? What kind of site are you building ;)
borisCallens
A: 

I can't do that since my viewdata is strongly typed. It would require me to fill the whole custom viewdata again. That can become ugly really fast ... :S

borisCallens
A: 

I found how to solve it, but not why it needs solving:

<%ViewData.Model.Colors.Model = ViewData.Model.Colors;%>            
<%Html.RenderPartial("~/Views/Color/_ColorList.ascx", ViewData.Model.Colors);%>

Any ideas?

borisCallens
+3  A: 

Probably an overload issues. You could call the RenderPartial(string, object, ViewDataDictionary) which makes all three parameters explicit.

One thing we're planning to change is if you call the overload RenderPartial(string, object), we'll pass the current ViewDataDictionary to the partial. We don't do that in the Beta, but it seems this is a very common scenario and will make this method more usable.

Haacked
Thanks, dat did the trick indeed.If I'm understanding your post correctly, I'm misunderstanding the difference between the passed model and the viewdata.Doesn't the ViewData already contain a reference to the model? Why need I pass it on twice?
borisCallens