Pass Viewdata as member from other viewdata to Ren

2019-08-18 03:34发布

问题:

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?

回答1:

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.



回答2:

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)); %>