Reputation: 4842
I've been trying to figure out a way to pass data to a nested master page. I'm using a nested master page because it allows me a secondary layer of navigation on my website, which can then be extended by other views which need that secondary layer of navigation.
For some reason I'm unable to access ViewData["field"]. Compiler throws the error that ViewData is not in the context of the nested master page. And I also can't use child actions, they too do not exist in the context of the nested master page.
This is how the nested master page has been declared: <%@ Master Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Curator.master.cs" Inherits="Atlasweb.Views.Shared.Curator" %>
I've tried changing the "Inherits" attribute to System.Web.Mvc.ViewMasterPage to see if it would allow me to access ViewData or child actions, but no luck.
Upvotes: 1
Views: 494
Reputation: 4842
The official way has been outlined by MSDN here.
Below is how I addressed my own error if it relates to you as well.
So this is what I figured out: Originally, when I added a new item, I selected "Nested Master Page". This construct might be older than MVC2, because MVC2 allows me to create a "MasterPage" and then add the attribute MasterPageFile which I can point to a [parent] master page to create nesting. Seems to work for me.
<%@ Master Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewMasterPage" %>
Upvotes: 2