无法加载资源:服务器响应状态为404(未找到)
Visual Studio 2019预览版。客户目标框架:.Net标准2.1服务器目标框架:.Net Core 3.1共享-目标框架:.Net标准2.1
dotnet --version3.1.200 ///预览版本
控制器代码
[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
}
}
组件代码
private async Task AddUser()
{
Console.WriteLine("Add user method");
try
{
await userService.CreateUser(_user);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
用户服务
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);
}
}
感谢您的帮助。
我遇到错误,代码无法找到Controller及其方法。我试图将用户从创建用户组件添加到数据库。无法加载资源:服务器回应了...