Home > Back-end >  Unable to fetch from controller - React/asp.net core Web API
Unable to fetch from controller - React/asp.net core Web API

Time:01-04

When I try to fetch data from the UserController I get returned Html for some reason. It is the index.html file under the React > Public folder. It should be returning the Users from the UserController.

I have a React frontend app which I have added ASP.NET Core Web API backend. enter image description here

============================Update===================================

Follow the tutorial you provide, and do the first 3 steps :

enter image description here

Then I get a solution within 2 projects(one react and one asp.net core 6 web api project)

Adding a controller with your code then I can access the api with url https://localhost:7119/api/user in the browser.

Modify the App.js file in the react project, adding the fetch method in the componentDidMount() function. Then start both the project.

CodePudding user response:

just fix your action route, API controller doesn't support any REST

[Route("~/api/user/getList")]
public ActionResult<IEnumerable<User>> List()

and make the same fetch route

htt.../api/user/getList
  •  Tags:  
  • Related