Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 17, 2007 09:05 AM by andyfreestyle
Dec 16, 2007 01:28 AM|LINK
why am i not able to access ViewData property in my aspx page. I did create a MVC View page item, and my partial class does derive from a ViewPage<> class.
I can not figure out, what i am missing in my aspx page, but i dont get access to ViewData, Html htmlhelper members. in generall, it doesnt understand anything about the viewpage ?
I am still on VS2008 beta, is this a problem with vs2008 beta ? or am i missing something in my aspx page ?
Dec 16, 2007 02:56 AM|LINK
How do you know you can't access it? Is it an intellisense issue or are you getting an exception? If it's intellisense - build your app and that should fix it.
Next, check the web.config and make sure that <system.web><pages><namespaces> contains "System.Web.Mvc".
Dec 16, 2007 03:09 AM|LINK
Both,I get a an error (using ViewData i get Object reference not set to an instance ) when i run the page and also no intellisense. My web.config does have "System.Web.Mvc". I did rebuild the whole project few times.
Any other ideas ?
Dec 16, 2007 03:17 AM|LINK
Are you using a typed view ViewPage<>?
If no, then there isnt any intellisence to be had for the ViewData since your just working against a Dictionary<string,object>. So you would access it like ViewData["ProductId"]. If you want intellisence on the ViewData change the page to inherit from ViewPage<Type>.
Also, when you get the "object reference not set to an instance" does your Url look like /Products/List or /Products/List.aspx?
If it looks like /Products/List.aspx, try going to /Products/List and see if it works. Replacing Products/List with the appropriate controller/action.
Dec 16, 2007 03:33 AM|LINK
I am using ViewPage<>.
1.when i try to debug from VS2008 beta, the browser is infact trying to acess .aspx. Which im not sure why it does ? Instead if i open up a browser, and try to acess /controller/action i dont get the error.
2. I think intellisense is a problem with VS2008 beta. I am not seeing Html helperclass object as well in my aspx, and am deriving my page class from ViewPage<>
Dec 16, 2007 03:44 AM|LINK
To allow for pressing F5 to debug you will want to set your default.aspx to the start page and then navigate to the page that you are trying to debug, since VS2008 is not aware that the pathing is different with an Mvc app then a normal WebForms website
(though it would be nice).
Dec 17, 2007 09:02 AM|LINK
Don't you only need to inherit from ViewPage<> if your using strongly typed objects?
How are you setting the ViewData ?
I mentioned the two ways in my post if thats any use:
Dec 17, 2007 09:05 AM|LINK
Intellisense doesn't appear to work correctly with Microsoft MVC using Visual Studio 2008 Beta 2. As this thread outlines -
http://forums.asp.net/t/1192768.aspx - installing Visual Studio 2008 RTM (I'm using the 90 day trial) fixes this. You shouldn't need to add any extra references or changes to your .aspx files with the 2008