我正在使用 MVC 4,我的项目中有一些区域,每个区域中有一些视图和部分视图:
Areas
AdminArea => one area and so on
Views
Customer
Customer.cshtml => my View
_CustomerDetails.cshtml => my partial View
在我的控制器 CustomerController 我有以下代码失败:
return PartialView("_CustomerDetails", model) => fails to find my partial view.
但是,如果我打电话
return PartialView("~/Areas/AdminArea/Views/Customer/_CustomerDetails.cshtml", model)
代码执行成功。
我的观点(不是部分观点)一切正常。我什至有一些部分视图(也在同一区域中)在没有指定完整路径的情况下呈现正常,但由于某种原因,对于其中的大多数,上面的代码在构造函数中失败,说:
The partial view '_CustomerDetails' was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Customer/_CustomerDetails.cshtml a.s.o. ... => and is searching in global not in Admin area.
有没有办法解决这个问题而不必在代码中指定我的 PartialViews 的完整路径?(就像我在 .cshtml 文件中那样传递 area="Admin" )。我没有使用任何自定义 ViewEngine,我在 Global.asax.cs 中调用了 AreaRegistration.RegisterAllAreas()。
谢谢, 塔玛什