开发者

ASP.Net MVC3 Menu with different Model as Content (partial view, renderpage?)

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="IndexMenuInne开发者_开发问答r">@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?


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:

@{ Html.RenderAction("Menu", "Site"); }

Where Site is your SiteController and Menu is something like:

public ActionResult Menu()
{
    return PartialView("Menu", new { LocationAdminModelCollection = new Model });
}

Disclaimer

Code not tested :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜