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

Blazor - WASM : Failed to load resource: the server responded with a status of 404 (Not Found)

$
0
0

I am getting below error, code is not able to find Controller and its methods. I am trying to add user to database from create user component.

Failed to load resource: the server responded with a status of 404 (Not Found)

Visual Studio 2019 Preview. Client - Target Framework : .Net Standard 2.1Server - Target Framework : .Net Core 3.1Shared - Target Framework : .Net Standard 2.1

dotnet --version3.1.200 ///Preview version

Controller Code

[Route("api/[controller]")][ApiController]public class UserInfoController : ControllerBase{    private readonly ApplicationDbContext dbContext;    public UserInfoController(ApplicationDbContext dbContext)    {        this.dbContext = dbContext;    }    [HttpPost]    public async Task<ActionResult<int>> Post(UserInfo user)    {        //some code here to add user to db    }}

Component Code

    private async Task AddUser()    {        Console.WriteLine("Add user method");        try        {            await userService.CreateUser(_user);        }        catch (Exception ex)        {            Console.WriteLine(ex.Message);        }    }

User Service

public class UserServices : IUserInfo{    private readonly IHttpService httpService;    private string url = "api/userinfo"; //Controller    public UserServices(IHttpService httpService)    {        this.httpService = httpService;    }    public async Task CreateUser(UserInfo user)    {        var response = await httpService.Post(url, user);    }}

Thanks for help.


Viewing all articles
Browse latest Browse all 4225

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>