'Blazor TypeError
Blazor application throws error whenever i try to call methods in api. I've tried different httprequest methods but nothing changed so far, still struggling to call api methods.
Error message: Unhandled exception rendering component: TypeError: Failed to fetch
System.Net.Http.HttpRequestException: TypeError: Failed to fetch
at System.Net.Http.BrowserHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
at System.Net.Http.Json.HttpClientJsonExtensions.d__91[[System.Collections.Generic.List1[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
at blazor.Pages.TableDesign.OnInitializedAsync() in C:\Users\Pc\source\repos\blazor\blazor\Pages\TableDesign.razor:line 124
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
This is the api method which i'm trying to call:
namespace Api.Controllers{
[ApiController]
   [Route("api/[controller]/[action]")]
  [HttpGet]
       public IActionResult GetColumns()
       {
           
           SqlConnection con = new SqlConnection(connection);
           SqlDataAdapter adp = new SqlDataAdapter("select*from dynamicTable",con);
           adp.SelectCommand.CommandType = CommandType.Text;
           DataTable dt = new DataTable();
            con.Open();
           adp.Fill(dt);
           foreach (var item in dt.Columns)
           {
              colList.Add(item.ToString());
           }
           con.Close();
           return Ok(colList);
       }
Blazor http request
List<string> colNames = new List<string>
            ();
protected override async Task OnInitializedAsync() =>colNames= await Http.GetFromJsonAsync<List<string>>("https://localhost:5001/api/table/GetColumns"); ```
            
        
							
						Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|
