【发布时间】:2021-06-04 09:19:59
【问题描述】:
[ProducesResponseType(200, Type = typeof(OperationResponse<Plan>))]
[ProducesResponseType(400, Type = typeof(OperationResponse<Plan>))]
[HttpGet("{id}")]
public async Task<IActionResult> Get([FromRoute] string id)
{
string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace();
Console.WriteLine("stack is " + t);
var plan = await _plansService.GetPlanById(id, userId);
if (plan == null)
return BadRequest(new OperationResponse<string>
{
IsSuccess = false,
Message = "Invalid operation",
});
return Ok(new OperationResponse<Plan>
{
Record = plan,
Message = "Plan retrieved successfully!",
IsSuccess = true,
OperationDate = DateTime.UtcNow
});
}
字符串 id 应该是 guid 类型,而我得到的是“搜索”这个词,而不是 id,它应该是特定产品的 guid。如何跟踪值.... 或映射?
【问题讨论】:
-
我认为您不了解
RouteParameter的工作原理:如果您想将 id 作为路由参数传递,您的 url 看起来像:api/plans/guid而不是api/plans/search -
那么在路由的发生方式上一定存在不匹配?
-
真的不能说,我只能说你的例子。如果这是您的控制器中唯一的
Get请求,那么我想它正在尝试路由到该端点。 -
我们不知道您的预期路线是什么样的,因为您没有发布该代码。我们不知道谁在提出实际请求,以及为什么他们认为他们的路线是正确的。但很明显,两者并不匹配。如果没有更多信息,这个问题无法回答。
标签: c# asp.net-web-api