Accepted answer

You have a typo in your fetch call:

Change fetch('values'); to fetch('api/values');.


on WeatherForecastController.cs file, look at line 11 [Route("[controller]")] that's the clue. 'weatherforecast' replaces the value of [controller] and the file has WeatherForecast init so the system automatically makes the connection.

for your case, you're routing to [Route("api/[controller]")] so you need to put 'api/' for your fetch request followed by class name.

Related Query

More Query from same tag