calling partial view from another controller inside @Html.RenderPartial

user2405469 picture user2405469 · Feb 3, 2014 · Viewed 7.1k times · Source

The directory structure is:

controllers -> HomeController, TableController                            
views -> home -> index.cshtml                                  
views -> Table -> Navigate.cshtml

The index.cshtml corresponds to the index method in the HomeController the navigate.cshtml is a partial view and corresponds to the Navigate method in the TableController. The navigate method's return type is PartialViewResult and returns:

PartialView("Navigate", Data);

The Index.cshtml has @Html.RenderPartial()...

if I wanted to call the partial view from the TableController, could I just say:

@Html.RenderPartial("~/Controllers/Table/Navigate");

So it renders the partial view returned by navigate method in the TableController.

Answer

Ashish Charan picture Ashish Charan · Feb 3, 2014

IF all you want to do is to include the partial view. Why not call it using action method. Like:

@Html.Action("Navigate","Table")

You can place this anywhere and it should work.