C#路由器Demo
//没有参数的路由控制器跳转 new RedirectToRouteResult("Default", new RouteValueDictionary(new { controller = "SysAdmin", action = "Login" })); //有参数的路由控制器跳转 new RedirectToRouteResult("Default", new RouteValueDictionary(new { controller = "SysAdmin", action = "Login", returnParamUrl = "http://www.baidu.com" }));
http://localhost:30893/?id=88
//-------------------------------------------
filterContext.Result = new RedirectToRouteResult("JumpLogin", new RouteValueDictionary(new { controller = "ShopUsers", action = "Login", id = "88", aa = "33", ii = "99" }));
http://localhost:30893/?id=88&aa=33&ii=99
//------------------------------------------
filterContext.Result = new RedirectToRouteResult("Default", new RouteValueDictionary(new { controller = "ShopUsers", action = "Login", id = "88", aa = "33", ii = "99" }));
http://localhost:30893/ShopUsers/Login/88?aa=33&ii=99
//------------------------------------------
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Shop", action = "Index", id = UrlParameter.Optional } //defaults: new { controller = "ShopUsers", action = "Login", id = UrlParameter.Optional } ); //routes.MapRoute( // name: "TestDemo", // url: "{controller}/{action}/{aa}/{bb}", // defaults: new { controller = "ShopUsers", action = "Login", aa = UrlParameter.Optional, bb = UrlParameter.Optional } // ); //routes.MapRoute( // name: "JumpLogin", // url: "{controller}/{action}", // defaults: new { controller = "ShopUsers", action = "Login" } // ); //Route jumpRoute = new Route("{controller}/{action}", new MvcRouteHandler()); //routes.Add("JumpLogin", jumpRoute); }
搜索
复制
标签:aa,C#,Demo,controller,action,new,Login,id,路由器 From: https://www.cnblogs.com/jankie1122/p/11108805.html