c# - MVC3/ Razor 错误 : The view or its master was not found or no view engine supports the searched locations

标签 c# asp.net-mvc-3 razor asp.net-mvc-routing

我有一个名为 Admin 的区域。 Visual Studio 中的文件夹结构是这样的:

Areas
   Admin
      Controllers
      Views

我有一个名为 AccountController 的 Controller ,其中有一个名为 Verify 的 Action。我在这个 Action 中有这行代码:

return View("EmailVerificationComplete");

但是,我得到这个错误:

未找到 View “EmailVerificationComplete”或其主视图,或者没有 View 引擎支持搜索的位置。搜索了以下位置: ~/Views/Account/EmailVerificationComplete.aspx ~/Views/Account/EmailVerificationComplete.ascx ~/Views/Shared/EmailVerificationComplete.aspx ~/Views/Shared/EmailVerificationComplete.ascx ~/Views/Account/EmailVerificationComplete.cshtml ~/Views/Account/EmailVerificationComplete.vbhtml ~/Views/Shared/EmailVerificationComplete.cshtml ~/Views/Shared/EmailVerificationComplete.vbhtml

这是为什么?为什么 MVC 不知道查看相对于 Admin 区域的 Views 文件夹?

我该如何解决?

谢谢,

萨钦

最佳答案

Why does MVC not know to look in the Views folder relative to the Admin area?

因为你的AccountController不在Admin里面区域。它可能在 ~/Controllers/AdminController.cs 中所以按照惯例 ASP.NET MVC 将查找 ~/Views/Shared~/Views/Account其相应的观点。

关于c# - MVC3/ Razor 错误 : The view or its master was not found or no view engine supports the searched locations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8926404/

相关文章:

.net - Windows 更新导致 MVC3 和 MVC4 停止工作

c# - MVC 4 - Html.Partial() 显示 DIV 内的 System.Namespace 文本(出现在页面上的 html 中)

c# - 将模型传递给局部 View

c# - Rhino Mocks 不抛出异常

c# - async partial void MyPartialMethod() 危险吗?

c# - 在 .net ReportViewer 控件中查看 MS Access Report

css - 样式未按我的预期显示

asp.net-mvc-3 - 使用 asp mvc 3、nhibernate 3.2 和 spring.net 1.3.2 没有 Hibernate Session 绑定(bind)到线程异常

c# - Razor 中 ViewModel 的模型名称

c# - 检查 EF 语句中的空实体