当我在Admin
区域内并使用属性路由映射我的路线时,它找不到视图,因为它不查看实际的区域视图文件夹,而只查看全局视图文件夹。
只有当我通过完整路径查看它然后才能显示它,否则它会引发错误。
错误
The view 'Authorize' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Authorize.aspx
~/Views/Home/Authorize.ascx
~/Views/Shared/Authorize.aspx
~/Views/Shared/Authorize.ascx
~/Views/Home/Authorize.cshtml
~/Views/Home/Authorize.vbhtml
~/Views/Shared/Authorize.cshtml
~/Views/Shared/Authorize.vbhtml
代码
[RoutePrefix("admin")]
public class HomeController : Controller
{
[Route]
public ActionResult Index()
{
return View("Authorize"); // Error
return View("~/Areas/Admin/Views/Home/Authorize.cshtml"); // Working
}
}
请注意,如果我禁用属性路由并切换回良好的旧路由,它将起作用。有什么方法可以解决这个问题,或者它按预期工作,我应该在我的所有区域应用完整路径?