Abhishek Ghosh

Abhishek Ghosh

  • NA
  • 40
  • 2.4k

Need to use a different Model in View Page than the Master Page RSS

Jun 18 2012 1:04 PM

I have a Master Page in MVC3(ASPX) where I have a sign in feature at the top . So it uses a Sign In Model(User Name,Password). As this is in the Master Page when In the view Page I try to use a different Model it shows an error,as it tries to access the Sign in Model.


Can anyone Help me in this regard?

Master Page

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<RecipeBlogASPX.Models.LogOnModel>" %>
<%@ Import Namespace="MVCControlsToolkit.Controls" %>
<%@ Import Namespace="MVCControlsToolkit.Controls.Validation" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <% ThemedControlsStrings.SetTheme("Test"); %>
    <title>
        <asp:ContentPlaceHolder ID="TitleContent" runat="server" />
    </title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/MenuStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/jquery-ui-1.8.9.custom.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/jquery.treeview.css" rel="stylesheet" type="text/css" />

</head>
<body>
   <div style="display:block; z-index:900">
    <table class="page" bgcolor="White">
        <tr>
            <td>
                <table>
                    <tr >
                        <td class="MenuHeader">
                            Welcome
                        </td>
                        <td class="MenuHeader1">
                            <%: Html.ActionLink("Member Login", "LogOn", "Account", null, new { @Style = "color:white;text-decoration:none;" })%>
                        </td>
                        <td class="editor-label1">
                            <%: Html.EditorFor(model => model.UserName)%>
                            <%: Html.ValidationMessageFor(model => model.UserName) %>
                        </td>
                        <td class="editor-label1">
                            <%: Html.EditorFor(model => model.Password)%>
                            <%: Html.ValidationMessageFor(model => model.Password) %>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
       
        <tr>
            <td>
                <br />
                <br />
            </td>
        </tr>
        <tr>
            <td >
                <asp:ContentPlaceHolder ID="MainContent" runat="server" />
            </td>
        </tr>
        <tr class="footer">
            <td align="center">
          
            </td>
        </tr>
    </table></div>
</body>
</html>


Content Page


<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<RecipeBlogASPX.Models.Ingredient>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Recipes -> List</h2>

<table>
    <tr>
        <th>
            Name
        </th>
        <th>
            Description
        </th>
        <th>
            Active
        </th>
        <th></th>
    </tr>

<% foreach (var item in Model) { %>
    <tr>
        <td>
            <%: Html.DisplayFor(modelItem => item.Name) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.Description) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.Active) %>
        </td>
        <td>
            <%: Html.ActionLink("Edit", "Edit", new { id=item.IngredientId }) %> |
            <%: Html.ActionLink("Details", "Details", new { id=item.IngredientId }) %> |
            <%: Html.ActionLink("Delete", "Delete", new { id=item.IngredientId }) %>
        </td>
    </tr>
<% } %>

</table>

</asp:Content>


Answers (1)