首页 > 解决方案 > ASP.NET Core Web Api 发布请求 404 Not Found

问题描述

我在控制器中有 post 方法:

    [Route("api/[controller]")]
    [ApiController]
    public class CompanyController : ControllerBase
    {
        private readonly ICompanyService _companyService;

        public CompanyController(ICompanyService companyService)
        {
            _companyService = companyService;
        }

        [HttpPost]
        [Route("saveParameters")]
        public StatusCodeResult  SaveCompanyValuationParameters([FromBody] CompanyValuationParametersDTO cvpDto)
        {
            var userName = Guid.NewGuid().ToString();
            var cvpDto1 = new CompanyValuationParametersDTO(27, 5, 4,
                5, 5, 5, userName);
            _companyService.SaveCompanyValuationParameters(cvpDto1);

            return StatusCode(201);
            //return CreatedAtAction("SaveCompanyValuationParameters", new { id = cvpDto1.Id }, cvpDto1);
        }
}

该方法的主体现在完全是一团糟,但我只想让它工作。我已经尝试了几种路由和返回类型,例如 StatusCodeResult、ActionResult、void 但我仍然无法从邮递员那里获得这个方法: 在此处输入图像描述 那么如何从邮递员那里获得 post 方法?我想我错过了一些简单的东西,但仍然无法弄清楚它到底是什么。

DTO:

    public class CompanyValuationParametersDTO
    {
        public int Id { get; set; }
        public int Salary { get; set; }
        public int ProfessionalGrowth  { get; set; }
        public int CompanyBenefits  { get; set; }
        public int CommunicationWithColleagues  { get; set; }
        public int EducationSector  { get; set; }
        public string UserName { get; set; }
}

标签: asp.netpostasp.net-corehttp-status-code-404asp.net-core-webapi

解决方案


推荐阅读