我正在尝试将用户浏览器中显示的 URL 从 Happy/Balloons 更改为 happy-times/balloon-pops。项目中有许多指向动作“Balloons”的链接,因此我不想更改这些链接,而是更改 global.asax,以便为同一动作显示不同的 URL。原始 MVC 路由如下所示:
routes.MapRoute(
"Happy.Balloons",
"Happy/Balloons/{groupId}/{paymentType}/{mortgageValue}/{province}",
new { controller = "Happy", action = "Balloons" },
new { groupId = "\\d+", paymentType = "\\d+", mortgageValue = "\\d+", province = "\\d+" }
);
我已将代码更改为
routes.MapRoute(
"Happy.Balloons",
"happy-times/balloon-pops/{groupId}/{paymentType}/{mortgageValue}/{province}",
new { controller = "Happy", action = "Balloons" },
new { groupId = "\\d+", paymentType = "\\d+", mortgageValue = "\\d+", province = "\\d+" }
);
我认为第二个参数是显示的 URL,但我得到一个:“您要查找的资源已被删除、名称已更改或暂时不可用。” 错误。有没有一种简单的方法可以通过修改 MapRoute 中的参数来做到这一点?如果是这样,怎么做?
问题跟进:在 mvc 中更改操作的 URL