MVC3/Razor错误:未找到视图或其主控或视图引擎不支持搜索的位置

Sac*_*nth 3 c# asp.net-mvc-routing razor asp.net-mvc-3

我有一个名为Admin的区域.Visual Studio中的文件夹结构如下:

Areas
   Admin
      Controllers
      Views
Run Code Online (Sandbox Code Playgroud)

我有一个名为AccountController的控制器,我在其中有一个名为Verify的Action.我在这个动作中有这行代码:

return View("EmailVerificationComplete");
Run Code Online (Sandbox Code Playgroud)

但是,我收到此错误:

未找到视图"EmailVerificationComplete"或其主页,或者没有视图引擎支持搜索的位置.搜索了以下位置:〜/ 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文件夹?

我该如何解决这个问题?

谢谢,

萨钦

Dar*_*rov 5

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

因为你AccountController不在这个Admin区域内.这也可能是在~/Controllers/AdminController.cs这样的约定ASP.NET MVC将查找~/Views/Shared或者~/Views/Account其相应的意见.

  • @Sachin,您是如何请求此控制器操作的?是`/ Admin/Account/Verify`还是只是`/ Account/Verify`?如果您在网址中没有"Area"前缀请求它,那就好像AccountController在您的根目录中一样. (4认同)

y62*_*ang 5

我有同样的问题.我发现当你发送某个动作的请求时,即使网址无效,mvc会根据传入的网址尝试匹配你的动作.如果找到匹配,(在我的情况下,它会转到正确的位置)执行控制器动作方法),但由于您传入的路径错误,因此无法找到关联的视图.