我正在尝试使用看起来像这样的网址
competitors/edit/d2d01443-118c-4a35-a783-465505f8d786?accountid=6af99691-2275-4629-8542-2eb52a34893f
并将其转换为类似的内容。基本上只需在竞争者参数之前移动帐户ID参数。
/competitors/edit/6af99691-2275-4629-8542-2eb52a34893f/d2d01443-118c-4a35-a783-465505f8d786
我尝试将此路由添加到路由配置的顶部,但是当我尝试新的网址时,我只收到404错误。谁能指出我做错了什么?谢谢!
routes.MapRoute(
name: "Competitors",
url: "{controller}/{action}/{accountid}/id",
defaults: new { controller = "Competitors", action = "Edit", accountid = UrlParameter.Optional, id = UrlParameter.Optional });
答案 0 :(得分:1)
我相信您需要在所有细分中使用大括号,否则需要将“id”硬编码到URL中以便匹配:
routes.MapRoute(
name: "Competitors",
url: "{controller}/{action}/{accountid}/{id}",
defaults: new { controller = "Competitors", action = "Edit", accountid = UrlParameter.Optional, id = UrlParameter.Optional });