Blazor-通过Http.GetJsonAsync传递参数

时间:2019-02-28 00:48:48

标签: c# blazor

在index.cshtml @functions中,我能够从数据库检索数据,同时发送参数selectedDate,如下所示:

trackList =等待Http.GetJsonAsync>(“ / api / Lopstat / Tracks /” + selectedDate.ToString(“ yyyy-MM-dd”));

如果我想随请求发送两个参数怎么办?这可能吗?

1 个答案:

答案 0 :(得分:0)

如果要发送两个参数,则可以为这些参数定义一个带有两个字段的类。此类将自动进行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);