【问题标题】:How can I add custom URL parameters to a MVC RedirectToAction如何将自定义 URL 参数添加到 MVC RedirectToAction
【发布时间】:2010-02-15 09:36:17
【问题描述】:

我目前有一个简单的 MVC RedirectToAction 操作:

return RedirectToAction("Edit", "Customers", new {Id = iNewId});

重定向到Cutomers/Edit/1

但是我想在 URL 中附加一些自定义值,这些值将被 javascript 使用,返回诸如 Cutomers/Edit/1#Tab1 之类的 URL

最好的方法是什么?

【问题讨论】:

    标签: c# asp.net-mvc


    【解决方案1】:
    routes.MapRoute("WithTarget", "{controller}/{action}/{id}#{target}");
    

    RedirectToAction("Edit", "Customers", new { id = iNewId, target = "Tab1" });
    

    RedirectToRoute("WithTarget", new { controller = "Customers", action = "Edit", id = iNewId, target = "Tab1" });
    

    但请记住,片段永远不会从客户端发送到 Web 服务器,因此无法在控制器操作中读取其值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 1970-01-01
      相关资源
      最近更新 更多