2

我有这个 ASP.NET webapi 程序,它运行顺利,帮助页面也能正常工作。

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

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 并单击转到查看时,它给了我一个错误并且什么也没有。

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

所以不知何故 Action 没有指向正确的视图页面,我不知道如何解决这个问题。

4

2 回答 2

2

我发现错误,文件夹区域,当它应该在根目录中时被意外放入了错误的目录

于 2014-01-07T22:40:29.940 回答
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 视频

于 2014-01-07T21:35:22.990 回答