MrM
MrM

Reputation: 22009

Can I Inherit something on my Site.Master page MVC?

I am trying to familiarize myself with the MVC environment. I would like to add a side menu on my default master page. I however need to add an inherit to get my data. Can I do that or I do I have to keep the 'Inherits="System.Web.Mvc.ViewMasterPage"'?

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>

<body>

<div class="page">
    <div id="header">
        <div id="title">
            <h1>My MVC Application</h1>
        </div>

        <div id="logindisplay">
            <% Html.RenderPartial("LogOnUserControl"); %>
        </div> 

        <div id="menucontainer">

            <ul id="menu">              
                <li><%= Html.ActionLink("Home", "Index", "Home")%></li>                    
                <li><%= Html.ActionLink("Summary", "Summary", "Home")%></li>                    
            </ul>

        </div>
    </div>

    <div id="main">
        <asp:ContentPlaceHolder ID="MainContent" runat="server">
        <div id="categories">
            <fieldset> 

                <% Html.RenderPartial("SideMenu", new ViewPage<DataLibrary.MenuOptions>().Model); %>
<!--I want to use ("SideMenu", Model) above -->
            </fieldset>
        </div>            
        </asp:ContentPlaceHolder>
        <div id="footer">
        </div>
    </div>
</div>

Upvotes: 3

Views: 648

Answers (2)

Eduardo Molteni
Eduardo Molteni

Reputation: 39453

You can inherit all your controllers from a main controller.

Then, in your MainController you can set all the data needed in the master page (all the global things)

Public MustInherit Class ApplicationController
    Inherits System.Web.Mvc.Controller

    Sub New()
        ViewData("SideMenu") = getSideMenu()
    End Sub

End Class

Later, in the Master page

<% Html.RenderPartial("SideMenu", ViewData("SideMenu")); %>

There are other ways to do it (this is just the way I do it), and in MVC 2.0 there is a new option to refer to a controller in the partial.

Upvotes: 0

Daniel Elliott
Daniel Elliott

Reputation: 22887

You don't need to Inherit, I believe you just need to use an import directive

such as

<%@ Import Namespace="DataLibrary" %>

Also, I think the line

<% Html.RenderPartial("SideMenu", 
                      new ViewPage<DataLibrary.MenuOptions>().Model); %>

should be

<% Html.RenderPartial("SideMenu", new MenuOptions()); %>

Kindness,

Dan

Upvotes: 2

Related Questions