ASP.Net MVC3 菜单以不同的模型作为内容(部分视图,渲染页面?)
我有一个页面,左侧有修复菜单。该部分视图需要与主页(内容)不同的模型。
主页/布局:
<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>
我可以这样做吗?
i have a page with a fix menu on the left side. This Partial View needs a different Model as the Main Page (Content).
Masterpage/Layout:
<body>
<div id="IndexMenu">
<div id="IndexMenuInner">@RenderPage("~/Views/Admin/part/_Menu.cshtml", new { LocationAdminModelCollection = new Model; })</div>
</div>
<div id="BodyContent">
@RenderBody()
</div>
Index/Content Page which where called at start:
@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>
My Menu:
@model Survey.WebApplication.Models.LocationAdminModelCollection
@{
Layout = null;
}
<div class="menuLocation">
</div>
Ho can i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将使用 Html.RenderAction 在控制器上呈现操作。在该操作中,您只需创建菜单所需的模型,并将 Menu.cshtml 部分视图作为 PartialViewResult 传递,
而不是
@RenderPage("~/Views/Admin/part/_Menu.cshtml", new { LocationAdminModelCollection = new Model; })
你会这样做:
其中 Site 是你的 SiteController,Menu 类似于:
免责声明
代码未测试 :)
I would use Html.RenderAction to render an Action on your Controller. In that action, you simply create the Model that your Menu needs, and pass out the Menu.cshtml partial View as a PartialViewResult
So instead of
@RenderPage("~/Views/Admin/part/_Menu.cshtml", new { LocationAdminModelCollection = new Model; })
you'd do:
Where Site is your SiteController and Menu is something like:
Disclaimer
Code not tested :)