BACKGROUND
I am trying to make use of Dashboard template on an MVC application I'm working on.
I am not sure how I can pass a ViewModel to the top bar I've called Header.
CODE
In my _Layout.cshtml
, I have split the HTML like so:
<body class="">
@Html.Partial("_Header")
<div class="page-container row-fluid">
@Html.Partial("_Sidebar")
<div class="page-content">
<div class="content">
@RenderBody()
</div>
</div>
</div>
</body>
I am guessing this is wrong because now I cannot pass a ViewModel to the header section, or if I can, we're not supposed to?
What is the right way of splitting this?
Instead of
@Html.Partial()
, use@Html.Action()
or@{ Html.RenderAction(); }
to call a[ChildActionOnly]
controller methods that initializes your model for the dashboard and returns a partial view, for exampleand in the layout
The alternative is that the model you use in each view using that layout would need a property which is the model used to generate your dashboard and then use
@Html.Partial("_Header", Model.yourDashBoardProperty)