【问题标题】:Am I calling RedirectToRoute correctly?我正确调用 RedirectToRoute 吗?
【发布时间】:2016-06-08 15:32:53
【问题描述】:

我打电话给RedirectToRoute 正确吗?


RouteConfig.cs:

routes.MapRoute(
    name: "Contact Us",
    url: "ContactUs",
    defaults: new {controller = "Home", action = "ContactUs"}
);

Handler.cs

HttpContext.Current.Response.RedirectToRoute("Contact Us", 
    new { controller = "Home", action = "ContactUs" }); 

【问题讨论】:

    标签: c# asp.net-mvc-4 redirecttoroute


    【解决方案1】:

    虽然你正在做的事情是有效的,但它也是不必要的和矫枉过正的。第二个参数保留给 RouteValueDictionary 或用于构建附加路由细节的对象,这些已被设置为命名路由的默认值。

    在您的情况下,您可以通过this overload 简单地使用路线的字符串名称。

    HttpContext.Current.Response.RedirectToRoute("Contact Us");
    

    【讨论】:

      猜你喜欢
      • 2022-12-09
      • 2018-02-14
      • 2017-04-04
      • 2014-02-28
      • 2015-06-25
      • 2022-01-08
      • 2011-08-07
      • 2011-09-26
      • 2019-05-03
      相关资源
      最近更新 更多