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:

  1. Wikipedia now has a definition for Real-Time Web
  2. Making cross domain JavaScript requests using XMLHttpRequest or XDomainRequest
  3. Defining the Kwwika API
Tagged with:
 
  • http://www.smartonlinedesign.co.uk Steve

    Thanks for this – I’ve just spent an hour or so doing the same thing!

Set your Twitter account name in your settings to use the TwitterBar Section.