
[英]asp.net mvc3: How to pass parameters from controller to a partial view which is designed to be called by RenderPage?
[英]ASP.Net MVC3 Menu with different Model as Content (partial view, renderpage?)
我在左侧有一个带有修复菜单的页面。 此局部视图需要不同的模型作为主页(内容)。
母版/布局:
<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在控制器上呈现一个Action。 在该操作中,您只需创建菜单所需的模型,然后将Menu.cshtml部分视图作为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 });
}
放弃
代码未测试 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.