【问题标题】:Blazor - passing arguments through Http.GetJsonAsyncBlazor - 通过 Http.GetJsonAsync 传递参数
【发布时间】:2019-02-28 00:48:48
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# blazor


    【解决方案1】:

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

    【讨论】:

    • 感谢您回答我在 Stackoverflow 上的第一个问题!我会试试这个解决方案。
    • 我发现这行得通,但我不得不将 HttpMethod.Get 更改为 HttpMethod.Post
    猜你喜欢
    • 2022-08-16
    • 2022-01-25
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多