Try our conversational search powered by Generative AI!

Calling partial views in Index method in page-type controller


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?

May 12, 2017 6:44

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!


May 16, 2017 18:06


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.

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.