public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
public class HomeController : Controller
{
public ActionResult About(int? id1,string name,int? id)
{
return View();
}
}
问题:
输入http://localhost:xx/Home/about,可以正常显示
http://localhost:xx/Home/about/1/2/3,找不到页面
http://localhost:xx/Home/about?id1=1&name=2&id=3,可以正常显示
怎样才可以在地址栏里面用/隔开各个参数并正确路由,也就是要第二种输入可以找到页面
------解决方案--------------------------------------------------------
修正下:
routes.MapRoute(
"test", // 路由名称
"Home/about/{id}/{name}/{ids}", // 带有参数的 URL
new { controller = "Home", action = "about"} // 参数默认值
);
加到你的默认路由前面。
view:
Html.ActionLink("test","About/1/2/3","Home")