0

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?

Kristijan Iliev
  • 4,901
  • 10
  • 28
  • 47
Boris Callens
  • 90,659
  • 85
  • 207
  • 305

2 Answers2

3

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
  • 58,045
  • 14
  • 90
  • 114
  • 1
    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? – Boris Callens Oct 27 '08 at 10:59
0

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
  • 21,574
  • 5
  • 44
  • 49