先看看我们例子用到的路由表

 routes.MapRouteWithName(
                name: "ProductDetail",
                url: "{Platform}/Product/{ProductID}",
                defaults: new { controller = "Home", action = "Product"}
               );
  • 方法1
protected internal RedirectToRouteResult RedirectToRoute(
    Object routeValues
)

eg:

 return RedirectToRoute(new
    {
         controller = "Home", //控制器
         action = "Product", //Action
         ProductID = 1, //参数
         nickName = "wahaha" //参数
    });
  • 方法2
protected internal RedirectToRouteResult RedirectToRoute(
    string routeName,
    Object routeValues
)

eg:

重定向到该路由

return RedirectToRoute("ProductDetail", new { Platform = "WeChat", ProductID = 1 });
  • 方法3
protected internal RedirectToRouteResult RedirectToRoute(
    RouteValueDictionary routeValues
)

eg:

 return RedirectToRoute(new System.Web.Routing.RouteValueDictionary(new { 
                action= "Product",
                controller = "Home",  
                ProductId =1 //参数
            }));
  • 方法4
protected internal virtual RedirectToRouteResult RedirectToRoute(
    string routeName,
    RouteValueDictionary routeValues
)

eg:
return RedirectToRoute("ProductDetail", new System.Web.Routing.RouteValueDictionary(new
{
    Platform = "WeChat",
    ProductID = 1

}));

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2022-01-10
  • 2021-06-10
  • 2021-11-12
  • 2022-12-23
猜你喜欢
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2021-11-28
  • 2021-09-01
相关资源
相似解决方案