[c#] How to Return partial view of another controller by controller?

I have an XXX.cshtml file in a Views\ABC folder. Its controller is ABC

I also have an action method in my DEF controller that return a Partialview("XXX" , xyzmodel)

I get a "view not found" error.

How to call that view from other controller

This question is related to c# asp.net-mvc

The answer is


The control searches for a view in the following order:

  • First in shared folder
  • Then in the folder matching the current controller (in your case it's Views/DEF)

As you do not have xxx.cshtml in those locations, it returns a "view not found" error.

Solution: You can use the complete path of your view:

Like

 PartialView("~/views/ABC/XXX.cshtml", zyxmodel);

Simply you could use:

PartialView("../ABC/XXX")