asp.net-mvc - 未找到 View 'Index' 或其主视图。

标签 asp.net-mvc asp.net-mvc-routing asp.net-mvc-areas

The view 'Index' or its master was not found. The following locations were searched:
~/Views/ControllerName/Index.aspx
~/Views/ControllerName/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx

我在使用 ASP.Net mvc 区域时遇到此错误。区域 Controller 操作被调用,但它似乎在“基本”项目 View 中查找 View ,而不是在区域 View 文件夹中。

最佳答案

您需要做的是为您的区域名称设置一个 token :

例如:

context.MapRoute(
        "SomeArea_default",
        "SomeArea/{controller}/{action}/{id}",
        new { controller = "SomeController", action = "Index", id = UrlParameter.Optional }
    ).DataTokens.Add("area", "YOURAREANAME");

关于asp.net-mvc - 未找到 View 'Index' 或其主视图。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2269220/

相关文章:

asp.net-mvc-3 - 在 MVC3 区域中使用 Web 表单

javascript - ASP.Net MVC 提交表单找不到方法 - 无法使用普通表单?

asp.net - 将 HTML 表格导出到 Excel

asp.net-mvc-3 - 将所有 View 重定向到一个 View 或从一个 View 重定向的最佳方式(例如 UnderConstructionView)

c# - 在 ASP.NET Core(以前的 ASP.NET 5)中嵌套路由的便捷方式是什么?

c# - ASP.NET MVC 不同的路由用于不同的 Action

asp.net - 如何在 ASP.NET MVC 2.0 的区域内共享 View ?

asp.net-mvc - 可以从全局路由访问 ASP.NET MVC3 区域 Controller ?

c# - MVC4 任务 <IEnumerable> 不可等待

c# - 将 Firebird 连接到 ASP.net WebAPI 项目