我希望每个链接都像:
mysite.com/England/English
mysite.com/France/French
mysite.com/Canada/French
要在此操作中打开:
public ActionResult Country(string country, string language)
但如果是关于:
mysite.com/About
应该去:
public ActionResult About()
其他一切都应该转到主页
public ActionResult Index()
我试过这样做:
routes.MapRoute(
"NewRoute",
"{id}",
new {controller = "Home", action = "Country", id = UrlParameter.Optional}
);
routes.MapRoute(
"AboutRoute",
"About",
New {controller = "Home", action = "About", id = UrlParameter.Optional}
);
答案 0 :(得分:1)
您应该在顶部放置更具体的路线。最后添加捕获所有路由。试试
routes.MapRoute(
"AboutRoute",
"About",
New {controller = "Home", action = "About"}
);
routes.MapRoute(
"NewRoute",
"{country}/{language}",
new { controller = "Home", action = "Country" }
);
routes.MapRoute(
"CatchAll",
"{*path}",
new { controller = "Home", action = "Index" }
);