将 Viewdata 作为成员从其他 viewdata 传递到 RenderPartial 使第一个为 null
强类型 SearchViewData
有一个名为 Colors 的字段,该字段又是一个 ColorViewData
。 在我的 /Colors.mvc/search
中,我根据给定的搜索条件填充此 viewData.Model.Colors
。 然后,根据几个因素,我渲染一组用户控件中的一个,这些控件能够使用 ColorViewData
渲染自身。
所以我最终会得到:
<%Html.RenderPartial("~/Views/Color/_ColorList.ascx", ViewData.Model.Colors);%>
这曾经工作得很好,但自从升级到 beta1 后,我的用户控件总是以 viewdata = null;
建议?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是过载问题。 您可以调用 RenderPartial(string, object, ViewDataDictionary) ,这使得所有三个参数都显式化。
我们计划更改的一件事是,如果您调用重载 RenderPartial(string, object),我们会将当前的 ViewDataDictionary 传递给部分。 我们在 Beta 版中没有这样做,但似乎这是一个非常常见的场景,并且将使该方法更可用。
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.
注意到同样的事情,我用以下方法修复了它,尽管我不确定这是否是“正确”的解决方案:
Noticed the same thing, I fixed it with the following, though I'm not sure if it's the "right" solution: