【问题标题】:Parsing parameter with bracket in URL解析URL中带括号的参数
【发布时间】:2019-10-02 06:22:55
【问题描述】:

我正在使用Jquery-bootgrid 创建表。在文档中将这种参数传递给控制器​​

current=1&rowCount=10&sort[columnName]=asc&searchPhrase=&id=b0df282a-0d67-40e5-8558-c9e93b7befed

我可以得到所有参数值,除了括号sort[columnName]=asc,我通过创建具有相同属性名称的类来获取参数,就像参数中一样

public class Bootgrid
{
    public int current { get; set; }
    public int rowCount { get; set; }
    public string searchPhrase { get; set; }
    public string[] sort{ get; set; } //can't get the value
}

请指教

【问题讨论】:

  • 我不明白你为什么要发送一个字符串数组,而你可以只发送一个用于排序类型的字符串变量
  • 你能试试输入IEnumerable<string>而不是string[]吗?
  • sort 只是一个字符串,而不是一个数组。你试过public string sort{get;set;} 吗?
  • 在任何情况下,查询参数数组都没有语法,每个平台/应用程序都使用自己的约定。有些重复相同的名称,例如foo=a&foo=b。有些使用值列表foo=a,b。有些人用方括号重复名称foo[]=a&foo[]=b

标签: c# asp.net-mvc rest jquery-bootgrid


【解决方案1】:

string[] 使用的是 int 索引而不是字符串索引。

例如,您可以使用字典。

public void GetTest(Dictionary<string, string> som)

这适用于 Test?som[key1]=value2

其中 som 包含值为“value2”的键“key1”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    相关资源
    最近更新 更多