当Razor引擎显然存在时,它找不到Index.cshtml页面

时间:2014-01-07 20:24:34

标签: c# asp.net asp.net-mvc-4 asp.net-web-api razorengine

我有这个ASP.NET webapi程序,该程序运行顺畅,帮助页面也正常运行。

Suddendly发生了一些事情,帮助页面将不再加载。

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/HelpPage/Views/Help/Index.aspx
~/Areas/HelpPage/Views/Help/Index.ascx
~/Areas/HelpPage/Views/Shared/Index.aspx
~/Areas/HelpPage/Views/Shared/Index.ascx
~/Views/Help/Index.aspx
~/Views/Help/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Areas/HelpPage/Views/Help/Index.cshtml
~/Areas/HelpPage/Views/Help/Index.vbhtml
~/Areas/HelpPage/Views/Shared/Index.cshtml
~/Areas/HelpPage/Views/Shared/Index.vbhtml
~/Views/Help/Index.cshtml
~/Views/Help/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml



Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:

    public ActionResult Index()
    {
        ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
        return View( Configuration.Services.GetApiExplorer().ApiDescriptions);
    }

  public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }

正确的文件显然位于“〜/ Areas / HelpPage / Views / Help / Index.cshtml”中,我已经在WebAPI教程之后注册了所有区域。由于某些未知原因,视图引擎无法找到它,帮助??

编辑:

好的我有点想出办法。 当我右键单击ActionResult并单击转到View时,它会给我一个错误并且什么都不做。

所以,我右键单击ActionResult并添加一个视图,它在〜/ Views / Help / Index.cshtml中创建一个新视图

所以某种程度上,Action没有指向正确的View页面,我也不知道如何解决这个问题。

2 个答案:

答案 0 :(得分:1)

我找到了错误, 如果文件夹“区域”应该位于根目录

中,则会意外地将其置于错误的目录中

答案 1 :(得分:0)

这是因为您在根和HelpController区域都有HelpPage,并且视图引擎无法确定要显示哪一个。

请在AppStart下打开您的RouteConfig.cs文件,并将根控制器类的命名空间添加到默认路由配置

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { 
                controller = "Home", 
                action = "Index", 
                id = UrlParameter.Optional 
            },
            namespaces: new[] { "yourrootcontrollernamespace" }
        );

结帐此YouTube视频