c# - ASP.NET MVC 路由不起作用

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

我有 2 条不同的路线:

context.MapRoute(
    "zyzzyva_default",
    "{urlTitle}",
    new { area = "zyzzyva", action = "Index", controller = "Home", urlTitle = UrlParameter.Optional }
);

第二个:

context.MapRoute(
    "Vip_default_vip_thankyou",
    "{partnername}-vip-thank-you",
    new { controller = "Vip", action = "ThankYou", partnername = "" },
    new string[] { "Web.Areas.Vip.Controllers" }
);

当我访问 mydomain.com/aaaa-vip-thank-you 时,它应该使用第二条路由,但我不明白为什么它使用第一条路由。

最佳答案

第一条路线太笼统了。

路由按照注册顺序找到第一个匹配项。

更改映射顺序。

context.MapRoute(
    "Vip_default_vip_thankyou",
    "{partnername}-vip-thank-you",
    new { controller = "Vip", action = "ThankYou", partnername = "" },
    new string[] { "Web.Areas.Vip.Controllers" }
);

context.MapRoute(
    "zyzzyva_default",
    "{urlTitle}",
    new { area = "zyzzyva", action = "Index", controller = "Home",urlTitle = UrlParameter.Optional }
);

关于c# - ASP.NET MVC 路由不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39978432/

相关文章:

C# 数组字典

c# - 绕过 Controller MVC 上的 Windows 身份验证

jquery - 如何在asp.net mvc中动态添加文本框

c# - 使用属性和约定路由

c# - 我怎样才能得到 Controller 操作的 MethodInfo,它将根据请求被调用?

c# - 对实体使用泛型

c# - 如何在 C# 中有效地获取字节数组的子集(前 N 个元素)?

c# - 如何将 Action 提取到成员函数中?

asp.net-mvc - MVC-路由,为什么我不能忽略默认值,匹配的路由不包含 'controller'路由值,这是必需的

jquery - 如何使用ajax从嵌套循环发送多个选定的复选框选中值?