问题描述
我有这个类在我的模型:
I've got this class in my Model:
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函数从实体框架检索查询结果
This is going to be used as input to a WebApi2 function to retrieve query results from Entity Framework.
该函数从输入取valPairs并用它来建立一个查询,排序由通过对,即。
The function takes the valPairs from input and uses it to build a query that sorts by the passed pairs, i.e.
CLI_RID=111111
DOC_NAME=Letter
将创建SQL:
WHERE CLI_RID = 111111
AND DOC_NAME = 'Letter'
我有点好奇,我怎么会通过ValPairs,用ajax和/或Web客户端?
GET或POST并不重要。
I'm kind of curious, how would I pass the ValPairs, using ajax and/or WebClient?GET or POST doesn't matter.
推荐答案
您可能需要添加一个新的类 ValPair ,像下面这样。
You may have to add a new class for
ValPair
, like the following.
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调用传递值的参数:
<$c$c>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&....
And you can pass values to the parameters via the following
GET
API call: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&...
.
如果您知道按键的名称这应该工作。
This should work if you know the names of the keys.
这篇关于复杂的输入WebApi2功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!