WebApi2 函数的复杂输入
Complex input to WebApi2 function
我的模型中有这个 class:
public class GetDocParams {
public string LogonTicket { get; set; }
public int CliRid { get; set; }
public string[] ValPairs { get; set; }
public string SortBy { get; set; }
public int StartRec { get; set; }
public int EndRec { get; set; }
}
这将用作 WebApi2 函数的输入,以从 Entity Framework 检索查询结果。
该函数从输入中获取 valPairs 并使用它来构建按传递的对排序的查询,即
CLI_RID=111111
DOC_NAME=Letter
将创建 SQL:
WHERE CLI_RID = 111111
AND DOC_NAME = 'Letter'
我有点好奇,如何使用 ajax and/or WebClient 传递 ValPairs?
GET 或 POST 无关紧要。
您可能需要为 ValPair
添加一个新的 class,如下所示。
public class GetDocParams {
public string LogonTicket { get; set; }
public int CliRid { get; set; }
public ValPair[] ValPairs { get; set; }
public string SortBy { get; set; }
public int StartRec { get; set; }
public int EndRec { get; set; }
}
public class ValPair {
public int CLI_RID { get; set; }
public string DOC_NAME { get; set; }
}
并且您可以通过以下 GET
API 调用将值传递给参数:
http://www.example.com/api/docs/getDocParams?LogonTicket=111&ValPairs[0][CLI_RID]=111111&ValPairs[0][DOC_NAME]=Letter&ValPairs[1][CLI_RID]=22222&ValPairs[1][DOC_NAME]=document&...
.
如果您知道键的名称,这应该可行。
我的模型中有这个 class:
public class GetDocParams {
public string LogonTicket { get; set; }
public int CliRid { get; set; }
public string[] ValPairs { get; set; }
public string SortBy { get; set; }
public int StartRec { get; set; }
public int EndRec { get; set; }
}
这将用作 WebApi2 函数的输入,以从 Entity Framework 检索查询结果。
该函数从输入中获取 valPairs 并使用它来构建按传递的对排序的查询,即
CLI_RID=111111
DOC_NAME=Letter
将创建 SQL:
WHERE CLI_RID = 111111
AND DOC_NAME = 'Letter'
我有点好奇,如何使用 ajax and/or WebClient 传递 ValPairs? GET 或 POST 无关紧要。
您可能需要为 ValPair
添加一个新的 class,如下所示。
public class GetDocParams {
public string LogonTicket { get; set; }
public int CliRid { get; set; }
public ValPair[] ValPairs { get; set; }
public string SortBy { get; set; }
public int StartRec { get; set; }
public int EndRec { get; set; }
}
public class ValPair {
public int CLI_RID { get; set; }
public string DOC_NAME { get; set; }
}
并且您可以通过以下 GET
API 调用将值传递给参数:
http://www.example.com/api/docs/getDocParams?LogonTicket=111&ValPairs[0][CLI_RID]=111111&ValPairs[0][DOC_NAME]=Letter&ValPairs[1][CLI_RID]=22222&ValPairs[1][DOC_NAME]=document&...
.
如果您知道键的名称,这应该可行。