我不知道为什么我在 ASP.NET Core MVC 3.1 中每次都会收到这个错误。我有一个观点,它就在它的位置。我只在某些区域遇到此错误。
InvalidOperationException: The view 'Dashboard' was not found. The following locations were searched:
/Areas/Admin/Views/Home/Dashboard.cshtml
/Areas/Admin/Views/Shared/Dashboard.cshtml
/Views/Shared/Dashboard.cshtml
最佳答案
十分之九, View 上的此错误是因为您忘记将 [Area("Admin")]
属性放在区域 Controller 的顶部。
Note: As you noted in your answer, this should not include the suffix
Area
.
虽然按照惯例,您的区域 View 是在 /Areas/{Area}/Views/
中搜索的,但没有任何努力来隐式确定 Controller 适用于某个区域。换句话说,.NET 完全依赖于 [Area()]
属性,而与您的 Controller 是否位于例如/Areas/{Area}/Controllers/
。出于组织目的,您可能无论如何都会将它们存储在那里,但 .NET 不关心这两种方式。
关于c# - 如何解决 ASP.NET Core MVC 中的 'View not found' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64992397/