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

时间:2022-10-10 03:29:22

Well i see this 2 properties but i cant understand the difference between them?
I cant seem to find any help anywhere about the PageData propriety.
so can any body help?

嗯,我看到这2个属性,但我不明白它们之间的区别?我似乎无法在任何地方找到任何有关PageData礼仪的帮助。所以身体有帮助吗?

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

thanks

谢谢

3 个解决方案

#1


12  

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。

#2


1  

I'm not 100% sure, but it looks like PageData is something from WebMatrix (MS's "light" web development environment). And ViewData is something that is fully supported in MVC. ViewData is in the System.Web.Mvc namespace, and therefore any MVC app will have it available.

我不是百分百肯定,但看起来像PageData是来自WebMatrix(MS的“轻型”Web开发环境)。 ViewData是MVC完全支持的东西。 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. Maybe it's not meant to be accessed from the controller side, like ViewData can be...?

在System.Web.WebPages命名空间中,PageData显然是(根据MSDN),但是我无法从我的MVC控制器访问PageData,即使我完全符合它。也许它不是要从控制器端访问,就像ViewData可以......?

There's some more info on PageData in this other * question here, but info on it around the web is surprisingly sparse (as you've probably found).

这里有另外一个*问题的关于PageData的更多信息,但是网络上的信息非常稀疏(正如你可能已经发现的那样)。

I hope that helps!

我希望有所帮助!

#3


-2  

Viewdata is a property of viewpage property and they both are in viewpage class....

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

#1


12  

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。

#2


1  

I'm not 100% sure, but it looks like PageData is something from WebMatrix (MS's "light" web development environment). And ViewData is something that is fully supported in MVC. ViewData is in the System.Web.Mvc namespace, and therefore any MVC app will have it available.

我不是百分百肯定,但看起来像PageData是来自WebMatrix(MS的“轻型”Web开发环境)。 ViewData是MVC完全支持的东西。 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. Maybe it's not meant to be accessed from the controller side, like ViewData can be...?

在System.Web.WebPages命名空间中,PageData显然是(根据MSDN),但是我无法从我的MVC控制器访问PageData,即使我完全符合它。也许它不是要从控制器端访问,就像ViewData可以......?

There's some more info on PageData in this other * question here, but info on it around the web is surprisingly sparse (as you've probably found).

这里有另外一个*问题的关于PageData的更多信息,但是网络上的信息非常稀疏(正如你可能已经发现的那样)。

I hope that helps!

我希望有所帮助!

#3


-2  

Viewdata is a property of viewpage property and they both are in viewpage class....

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