我在控制器中有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,但仍然无法从邮递员到达此方法: 那么如何从邮递员那里获得邮寄方式呢?我想我缺少一些简单的东西,但仍然无法弄清楚到底是什么。
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; }
}