【发布时间】:2019-02-28 00:48:48
【问题描述】:
在 index.cshtml @functions 中,我可以从 DB 中检索数据,同时发送参数 selectedDate,如下所示:
trackList = await Http.GetJsonAsync>("/api/Lopstat/Tracks/" + selectedDate.ToString("yyyy-MM-dd"));
如果我想在请求中发送两个参数怎么办?这可能吗?
【问题讨论】:
在 index.cshtml @functions 中,我可以从 DB 中检索数据,同时发送参数 selectedDate,如下所示:
trackList = await Http.GetJsonAsync>("/api/Lopstat/Tracks/" + selectedDate.ToString("yyyy-MM-dd"));
如果我想在请求中发送两个参数怎么办?这可能吗?
【问题讨论】:
如果要发送两个参数,可以为这些参数定义一个包含两个字段的类。此类将自动进行 JSON 编码并作为字符串发送
您可以使用如下所示的 SendJsonAsync 方法:
public static async Task<T> SendJsonAsync<T>(this HttpClient httpClient, HttpMethod method, string requestUri, object content)
// And this is how you can use it in your code...
trackList = await Http.SendJsonAsync<Change this to the return type>( HttpMethod.Get, "/api/Lopstat/Tracks", MyObject);
【讨论】: