Calling partial views in Index method in page-type controller

Vote:
 

I have created one homepagetype controller and in index method i written navigation-bar code. I want that navigation-bar code in all pages so i created one partialview under homepagetype-controller and calling that in index method and in all view pages.But it's not working.Can any one help me how to solve this?

#178505
May 12, 2017 6:44
Vote:
 

Hi Pawan,

If this Navigation bar is on all pages, I recommend moving the Navigation bar code to its own action/controller. From there, you can call this action like this in the _Layout.cshtml file (or in any other View):

@Html.Action("GetNavigationBar", "MasterpageComponents", new { controllerType = string.Empty }) //GetNavigationBar == action name, MasterpageComponents == controller name

One thing to note - child actions can potentially hinder performance, so please be cautious in the number of child actions that are being used on each page type. Hope this helps!

-RJ

#178650
May 16, 2017 18:06
Vote:
 

Hi,

Another solution is to use a ViewModel that contains the navigation in a property as well as the CurrentPage.

Having Partial Views with their own controllers risks leading to bad performance.

#178752
May 19, 2017 22:05
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.