Can I inherit something on my MVC site page?

I am trying to get familiar with the MVC environment. I would like to add a side menu to my default home page. However, I need to add inheritance to get my data. Can I do this or do I need to save "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>

+3
source share
2 answers

You do not need to inherit, I believe that you just need to use the import directive

such as

<%@ Import Namespace="DataLibrary" %>

Also, I think the line

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

it should be

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

Kindness,

Dan

+2
source

You can inherit all your controllers from the main controller.

MainController , ( )

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

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

End Class

,

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

( , ), MVC 2.0 .

0

Source: https://habr.com/ru/post/1728483/


All Articles