How to Return partial view of another controller by controller?

前端 未结 3 710
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 07:58

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

I also have an action method in my DEF co

3条回答
  •  既然无缘
    2020-12-04 08:40

    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);
    

提交回复
热议问题