Master does not have a definition for ViewData (ASP.NET MVC2)
I’m building an ASP.NET MVC2 web application and I was trying to access ViewData in my Site.Master page and I kept getting “master does not have a definition for ViewData”.
<%= ViewData["topic"] %>
The simple answer was that my Master Page was not an ASP.NET MVC2 master page. Somehow I had a standard master page.
So, all I did was swap the existing page declaration
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.Master.cs" Inherits="HubSubscriber.Views.Shared.Site" %>
With an ASP.NET MVC2 declaration:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
And bingo! ViewData was now accessible from my master page.
This post on Passing Data to View Master Pages may also be useful.
Related posts:
-
http://www.smartonlinedesign.co.uk Steve
About Phil Leggetter
My name is Phil Leggetter and I'm a Developer Evangelist at Pusher, a Real-Time Web Software and Technology Evangelist and Consultant, software engineer, team leader, line manager, micropreneur, product developer, Twitter user and a keen user of social media. For more information see the About Phil Leggetter page.
Social
Tags
.NET Ajax API APIs ASP.NET MVC Bing Blogging C# cloud comet Community DataSift Facebook Google Hardware http streaming ian sanders ideas Internet JavaScript Kwwika Life Mapping Microsoft Mobile Phones pubsubhubbub pusher real-time real-time data real-time push real-time web realtime RSS RTRIA Scotland silverlight Social Media Software Development Superfeedr truly real-time truly real-time web Twitter web 2.0 websockets Whinge









