在局部设置ViewData的项目在视图中读取 [英] Setting ViewData item in a Partial to be read in a View

查看:153
本文介绍了在局部设置ViewData的项目在视图中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个观点,我称之为的RenderPartial。

I have a View which I call RenderPartial.

在用户控件部分我设置计算机[IsTextAreaVisible] =真;

In the Partial usercontrol I set ViewData["IsTextAreaVisible"] = true;

在调用的RenderPartial 后,我查看我检查 ViewData的价值[IsTextAreaVisible]

In my View after the call to RenderPartial I check the value of ViewData["IsTextAreaVisible"].

即使用户控件已经设置,查看认为,这为null。

Even though the usercontrol had set it, the View thinks that it is null.

这是一个bug,或是否有更好的方法?

Is this a bug or is there a better approach?

感谢

推荐答案

这是事先设计好的。

每个部分观点得到它自己的视图数据的副本,以便作出的任何变动不会玷污原件。你想要做什么,我们已经EX pressly禁止的。

Each partial view gets it own copy of the view data so that any changes it makes don't taint the original. What you want to do, we've expressly prohibited.

这篇关于在局部设置ViewData的项目在视图中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆