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

发布于 2024-12-05 11:03:13 字数 1729 浏览 2 评论 0原文

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

我的项目具有以下结构:

  • 区域
    • 员工报告
      • 控制器
        • 报告
      • 观看次数
        • 报告
          • 列表
          • ...
  • 控制器
    • 登录
  • 视图
    • 登录
      • ...
    • 登录

EmployeeReportAreaRegistration.cs :

public class EmployeeReportAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "EmployeeReport";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        var routes = context.Routes;

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

    }
}

Global.asax:

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

        routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Default", action = "Welcome", 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

那么,我在哪里出错了?

谢谢

I have problem with create ulr routing for asp.net mvc3 application.

My project has this structure :

  • Areas
    • EmployeeReport
      • Controllers
        • Report
      • Views
        • Report
          • List
          • ....
  • Controllers
    • Login
  • Viwes
    • Login
      • ...

EmployeeReportAreaRegistration.cs :

public class EmployeeReportAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "EmployeeReport";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        var routes = context.Routes;

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

    }
}

Global.asax :

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

        routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Default", action = "Welcome", 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

Well, where I do mistake ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

唠甜嗑 2024-12-12 11:03:13

修改后的答案:

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

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

context.MapRoute(...);

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

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

revised answer:

Adding to Context.Routes directly means it loses any information about Areas.

Either use AreaRegistration.MapRoute (which is overriden to put in the Area information).

context.MapRoute(...);

Or put the area in the DataTokens parameter (not the defaults parameter as you have done here)

context.Routes.MapRoute("", "url", new {...}, null, new {area = this.AreaName});
稀香 2024-12-12 11:03:13

您所在区域的文件夹结构应如下所示:

  • 区域
    • 员工报告
      • 控制器
      • 观看次数

Your folder structure for your area should look like so:

  • Areas
    • EmployeeReport
      • Controllers
      • Views
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文