简体   繁体   English

asp.net MVC 3中的ViewData和PageData有什么区别?

[英]what is the difference between ViewData & PageData in asp.net MVC 3?

Well i see this 2 properties but i cant understand the difference between them? 好吧,我看到这2个属性,但我不明白它们之间的区别?
I cant seem to find any help anywhere about the PageData propriety. 我似乎无法找到任何有关PageData礼仪的帮助。
so can any body help? 所以身体有帮助吗?

@
{
 Viewdata["something"] = 1;
 PageData["something"] = 2;
}

thanks 谢谢

PageData is a property of WebPages that Razor is built on PageData是Razor构建的WebPages的属性

[it] Provides array-like access to page data that is shared between pages, layout pages, and partial pages. [it]提供对页面,布局页面和部分页面之间共享的页面数据的类似数组的访问。

http://msdn.microsoft.com/en-us/library/system.web.webpages.webpagebase.pagedata(v=VS.99).aspx http://msdn.microsoft.com/en-us/library/system.web.webpages.webpagebase.pagedata(v=VS.99).aspx

ViewData is a property of ViewPage and provides a method of passing data between a controller and a page. ViewData是ViewPage的一个属性,它提供了一种在控制器和页面之间传递数据的方法。

Gets or sets a dictionary that contains data to pass between the controller and the view. 获取或设置一个字典,其中包含要在控制器和视图之间传递的数据。

http://msdn.microsoft.com/en-us/library/system.web.mvc.viewpage.viewdata.aspx http://msdn.microsoft.com/en-us/library/system.web.mvc.viewpage.viewdata.aspx

ViewData is accessible via the controller, PageData isn't. 可以通过控制器访问ViewData,而不是PageData。

I'm not 100% sure, but it looks like PageData is something from WebMatrix (MS's "light" web development environment). 我不是百分百肯定,但看起来PageData是来自WebMatrix(MS的“轻型”Web开发环境)。 And ViewData is something that is fully supported in MVC. ViewData是MVC完全支持的东西。 ViewData is in the System.Web.Mvc namespace, and therefore any MVC app will have it available. ViewData位于System.Web.Mvc命名空间中,因此任何MVC应用程序都可以使用它。

PageData is apparently (according to MSDN) in the System.Web.WebPages namespace, but I can't access PageData from my MVC controllers, even if I fully qualify it. 在System.Web.WebPages命名空间中,PageData显然是(根据MSDN),但是我无法从我的MVC控制器访问PageData,即使我完全符合它。 Maybe it's not meant to be accessed from the controller side, like ViewData can be...? 也许它不是要从控制器端访问,像ViewData可以......?

There's some more info on PageData in this other StackOverflow question here , but info on it around the web is surprisingly sparse (as you've probably found). 还有在这个其他的StackOverflow问题上PageData一些更多的信息在这里 ,但它的信息在网络周围出奇地稀疏(如你可能会发现)。

I hope that helps! 我希望有所帮助!

Viewdata是viewpage属性的属性,它们都在viewpage类中....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM