asp.net - 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; }
}
解决方案
推荐阅读
- python - 如何概括 NumPy 数组列表的交织?
- java - Spring Cloud API Gateway Routing 基于 JWT 中的数据
- amazon-web-services - Flutter 无法使用 Web Socket Channel 连接到 AWS
- javascript - 访问输入数组中的特定输入
- python - 如何从所有列的列表中删除 nan 并将某些包含列表的列转换为字符串和 int?
- android - 如何将 Activity 类中的 finish() 作为函数参数传递(这样代码可以在 Kotlin 中重用)?
- javascript - 创建将当前年/月/日/小时插入 URL 的 javascript 小书签?
- python - Flask – 具有共享功能的多个子域
- android - 如何使用勺子运行特定的浓缩咖啡测试类/测试用例?
- python - 为什么我会收到 ConnectionResetError: [WinError 10054] 现有连接被远程主机强行关闭?