Reputation: 43
I have some issues with rendering strongly type partial view in layout view.
I want to make avalible the partial view(menu) in all pages/view. the problem I face is where to put the action for partial view to populate it from DB on page load.
thanks
---------------------- My code is--------------------
partial view inside shared folder.
@model List<Menu>
@foreach(var item in Model){// here is the html/model item inside to display}
--------------------------------------
HomeView.chtml inside home folder
@model List<homemodel>
.... here goes html code/ plus homemodel loop/data etc.
------------------------------
HomeController{
public ActionResult HomeView()
{
.........return view();
}
public PartialViewResult partialmenu()
{
// data from db
return partialview(partialobject as list);
}
------------------------
layoutview.chtml
--html code---
{@ Html.renderpartial("partialview");}
.. html code...
Upvotes: 0
Views: 2866
Reputation: 1537
where to put the action for partial view to populate it from DB on page load.
every view has it's own controller..regardless if it is partial or not...therefore you could populate your view on it's own controller...
Upvotes: 0
Reputation: 17288
I want to make available the partial view(menu) in all pages/view. the problem I face is where to put the action for partial view to populate it from DB on page load.
Write in layout: Html.RenderAction('MyMenu')
OR Html.Action('MyMenu')
and then populate it from any source. Your action will return strongly typed model.
Upvotes: 0