Sta*_*tan 15 c# asp.net-mvc asp.net-mvc-areas attributerouting asp.net-mvc-5
当我在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
Run Code Online (Sandbox Code Playgroud)
码
[RoutePrefix("admin")]
public class HomeController : Controller
{
[Route]
public ActionResult Index()
{
return View("Authorize"); // Error
return View("~/Areas/Admin/Views/Home/Authorize.cshtml"); // Working
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,如果我禁用属性路由并切换回旧的路由,它将起作用.有什么方法可以解决这个问题,或者它是按照预期的方式工作的,我应该在所有方面应用完整的路径?
Jam*_*mes 24
您需要将[RouteArea("")]属性添加到控制器:
[RouteArea("Admin")]
public class HomeController : Controller
Run Code Online (Sandbox Code Playgroud)
你可以在这里找到文档.