public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // 路由名称
"{controller}/{action}/{id}", // 带有参数的 URL
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
);
routes.MapRoute(
"willian",
"{path}/{ac}/{paras}/{para}",
new { controller = "Home", action = "test", paras = "1", para = "2" }
);
}
Global文件中写入自己的路由规则
public ActionResult Index(string paras, string para)
{
ViewData["Message"] = paras + " " + para;
return View("/Views/Home/Index.aspx");
}
Controller里写自己需要的Action,参数的名字必须和路由设置的参数名一致
需要多规则的时候在Global文件中继续添加规则即可