14

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?

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

thanks

Karim
  • 6,113
  • 18
  • 58
  • 83
  • 2
    Hi Karim, it might be that in your code snippet you have "ViewPage", but in your question you have "PageData". – dizzwave Jun 21 '11 at 17:01

3 Answers3

14

PageData is a property of WebPages that Razor is built on

[it] Provides array-like access to page data that is shared between pages, layout pages, and partial pages.

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.

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

ViewData is accessible via the controller, PageData isn't.

David Glenn
  • 24,412
  • 19
  • 74
  • 94
  • thanks, but this issue is very confusing , also do you happen to know if any of these 2 have a relation to HttpContext.Current.Items[]? i was using this before asp.net mvc in web forms. but it reminds of these 2 proprities. – Karim Jun 21 '11 at 19:08
2

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 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...?

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).

I hope that helps!

Community
  • 1
  • 1
dizzwave
  • 4,013
  • 1
  • 19
  • 16
-2

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

Gaurav Agrawal
  • 4,355
  • 10
  • 42
  • 61