C#路由器Demo

 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);
        }

 

posted on 2022-10-28 18:00  Jankie1122  阅读(67)  评论(0编辑  收藏  举报