Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
BlazorStudents.Pages.StudentComp.OnInitializedAsync() in StudentComp.razor
-
    Student stds = new Student();
    string ids = "0";
    bool showAddrow = false;
    protected override async Task OnInitializedAsync()
    {
        student = await Http.GetJsonAsync<Student[]>("/api/Students");
    }
    void AddNewStudent()
    {
        stds = new Student();
    }


What I have tried:

it is not working,
protected override async Task OnInitializedAsync()
   {
       student = await Http.GetJsonAsync<Student[]>("/api/Students");
   }
Posted
Updated 18-Dec-20 20:45pm

1 solution

Error is quite self explanatory: Invalidoperationexception: an invalid request URI was provided. The request URI must either be an absolute URI or baseaddress must be set
"/api/Students" is not a valid URI. Easiest test is to put in browser and see if you get back a valid response.

You are missing a url, something like:
https://mytestweb.com/api/students


The end point you are using must be hosted on some server for access. You are missing to add that server part to the end point. A complete valid end point.
Quote:
This instance represents a relative URI, and this property is valid only for absolute URIs.

Refer: Uri.AbsoluteUri Property (System) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900