Pass Viewdata as member from other viewdata to RenderPartial makes the first null

天涯浪子 提交于 2019-12-13 20:28:24

问题


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


来源:https://stackoverflow.com/questions/233261/pass-viewdata-as-member-from-other-viewdata-to-renderpartial-makes-the-first-nul

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!