Blazor - 通过Http.GetJsonAsync传递参数

问题描述 投票:0回答:1

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

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

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

c# blazor
1个回答
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);   
© www.soinside.com 2019 - 2024. All rights reserved.