【问题标题】:Redirect to action with querystring array使用查询字符串数组重定向到操作
【发布时间】:2020-12-04 13:38:04
【问题描述】:

我正在尝试使用查询字符串数组重定向到操作:

string[] variantIds = new { 
  "test1",
  "test2",
};

return RedirectToAction("SamplesOrderStep3", new { variantIds });

但这会重定向到

sample-order-step3?variantIds=System.String%5B%5D

如何让它去

sample-order-step3?variantIds=test1&variantIds=test2

【问题讨论】:

    标签: c# asp.net-mvc asp.net-mvc-routing


    【解决方案1】:

    看起来您无法直接使用重定向到操作进行重定向 - 最后我使用了混合或 Url.ActionRedirect

    return Redirect($"{Url.Action("SamplesOrderStep3")}?variantIds={string.Join("&variantIds=", variantIds)}");
    

    【讨论】:

      【解决方案2】:

      我相信这个'How do you link to an action that takes an array as a parameter (RedirectToAction and/or ActionLink)?' 描述了您的情况,Lee Smith 的答案似乎相似且有用。

      【讨论】:

        【解决方案3】:

        我相信如果你把它转换成带分隔符的字符串会更好

        string variantIdsString = "test1,test2";
        

        或者尝试使用字符串列表而不是数组。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2022-03-24
          • 1970-01-01
          • 2014-11-03
          • 2012-10-02
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多