我有一个页面,左侧有一个修复菜单。此部分 View 需要不同的模型作为主页(内容)。
母版页/布局:
<body>
<div id="IndexMenu">
<div id="IndexMenuInner">@RenderPage("~/Views/Admin/part/_Menu.cshtml", new { LocationAdminModelCollection = new Model; })</div>
</div>
<div id="BodyContent">
@RenderBody()
</div>
开始时调用的索引/内容页面:
@model Survey.WebApplication.Models.ChecklistDetailsModel
@{
ViewBag.Title = "Survey Administration";
Layout = "~/Views/Admin/_Layout.cshtml";
}
<link href="@Url.Content("~/Content/Admin/Menu.css")" rel="stylesheet" type="text/css" />
<div id="IndexSubMenu">sub_Menu</div>
<div>
<div id="IndexMenuInner"></div>
</div>
我的菜单:
@model Survey.WebApplication.Models.LocationAdminModelCollection
@{
Layout = null;
}
<div class="menuLocation">
</div>
我可以这样做吗?
最佳答案
我将使用 Html.RenderAction 在 Controller 上呈现操作。在该操作中,您只需创建菜单所需的模型,并将 Menu.cshtml 部分 View 作为 PartialViewResult 传递出去
因此,不要使用 @RenderPage("~/Views/Admin/part/_Menu.cshtml",而是 new { LocationAdminModelCollection = new Model; })
你会这样做:
@{ Html.RenderAction("Menu", "Site"); }
其中 Site 是您的 SiteController,Menu 类似于:
public ActionResult Menu()
{
return PartialView("Menu", new { LocationAdminModelCollection = new Model });
}
免责声明
代码未测试:)
关于asp.net-mvc-3 - ASP.Net MVC3 菜单以不同的模型作为内容(部分 View ,渲染页面?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5676184/