Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Are there any differences when calling an API with Blazor in different render modes?

$
0
0

I'm having problems calling my API from a Blazor app with Fluent UI (if that matters). When I start the app, in the OnInitializedAsync() method, I'm calling the API that should return a list of ids, and after that I'm calling my API again to get detailed information about specific id.

The problem is that, when I call the second API with a given id, the id parameter is not sent to the API. Any suggestions are welcome.

There are code snippets:

protected override async Task OnInitializedAsync(){    FhirIgResponse res = await mappingService.GetBundles();    bundleOptions = res.Results;    selectedBundle = res.Results.First();    await OnBundleSelect();}private async Task OnBundleSelect(){    try    {        if (!string.IsNullOrWhiteSpace(selectedBundle))        {            execScript = await mappingService.GetExecScript(selectedBundle);        }        else        {            toastService.ShowError("Please select a valid Id");        }    }    catch (Exception ex)    {        toastService.ShowError($"OnBundleSelect with parameter: {selectedBundle} and error: {ex.Message}.");    }}private async Task<T> SendRequestAsync<T>(string url, HttpMethod method, object? parameters = null){        if (string.IsNullOrWhiteSpace(url))        {            throw new ArgumentException($"Parameter ${nameof(url)} is required.");        }        using (HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, url))        {            if (method ==  HttpMethod.Post)            {                httpRequestMessage.Content = JsonContent.Create(parameters,                    new MediaTypeHeaderValue("application/json"),                    new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull });                await httpRequestMessage.Content.LoadIntoBufferAsync();            }            HttpResponseMessage httpResponseMessage = await _HttpClient.SendAsync(httpRequestMessage);            if (httpResponseMessage.StatusCode != System.Net.HttpStatusCode.OK)            {                throw new Exception($"Error sending request the status code was: {httpResponseMessage.StatusCode}. The response message was: {await httpResponseMessage.Content.ReadAsStringAsync()}");            }            string content = await httpResponseMessage.Content.ReadAsStringAsync();            return Utilities.ParseContentToT<T>(content);        }}

I tried to change the render mode of Blazor, but without any results.


Viewing all articles
Browse latest Browse all 4839

Trending Articles