【发布时间】:2013-09-06 16:44:37
【问题描述】:
我正在使用 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()。
谢谢, 塔玛什
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing