asp.net mvc 3 领域和 url 路由配置

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

我在为 asp.net mvc3 应用程序创建 ulr 路由时遇到问题。

我的项目具有以下结构:

  • 领域
    • 员工报告
      • Controller
        • 报告
      • 观看次数
        • 报告
          • 列表
          • ...
  • Controller
    • 登录
  • 浏览次数
    • 登录
      • ...

EmployeeReportAreaRegistration.cs:

公共(public)类 EmployeeReportAreaRegistration : AreaRegistration
{
    公共(public)覆盖字符串区域名称
    {
        得到
        {
            返回“员工报告”;
        }
    }

    公共(public)覆盖无效RegisterArea(AreaRegistrationContext上下文)
    {
        var 路由 = context.Routes;

        paths.MapRoute(null, "vykazy/vykazy-zamestnance", new { Area = "EmployeeReport",controller = "Report", action = "List"});

    }
}

全局.asax:

routes.MapRoute(null, "prihlasit", new {controller = "登录", action = "登录"});

        paths.MapRoute("默认", "{controller}/{action}/{id}", new {controller = "默认", action = "欢迎", id = UrlParameter.Optional });

When i try load "http://localhost/app_name/vykazy/vykazy-zamestnance
i get this exception :

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

那么,我哪里出错了?

谢谢

最佳答案

修改后的答案:

直接添加到 Context.Routes 意味着它会丢失有关区域的任何信息。

要么使用AreaRegistration.MapRoute(它被覆盖以放入区域信息)。

context.MapRoute(...);

或者将该区域放入 DataTokens 参数中(而不是像您在此处所做的那样使用默认参数)

context.Routes.MapRoute("", "url", new {...}, null, new {area = this.AreaName});

关于asp.net mvc 3 领域和 url 路由配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7471751/

相关文章:

asp.net - precompiledApp.config 的目的是什么?

c# - 根据 Msdn GridView.DataKeyNames 必须设置,如果我们想更新数据库

c# - 尝试从 Web 应用程序访问报告服务时,Internet Explorer 导致 IIS 500 错误

asp.net-mvc-3 - 部署在Azure上的MVC应用程序无法连接到SQL Azure数据库,但可以通过SSMS连接

asp.net-mvc-3 - RedirectToAction retcode 错误处理最佳实践

.net - 在asp.net 4.0 mvc中显示viewdata

asp.net - AutoValidateAntiForgeryToken 与 ValidateAntiForgeryToken

ASP.Net:尝试处理 http://localhost:5957/http://yahoo.com 时出现 HTTP 400 错误请求错误

javascript - Emberjs不会加载jquery/javascript,在页面中插入html时运行代码

php - CakePHP - 如何使用 slug 进行反向路由?