使用ASP.NET Core 2.2,我可以执行以下ApiController操作:
[ApiController]
public class PostController : Controller
{
[HttpGet("posts/{postId:int:min(1)}")]
public async Task<IActionResult> GetByPostId([FromQuery]GetByPostIdRequest request)
{
}
}
GetByPostIdRequest
如下:
public class GetByPostIdRequest
{
[FromRoute]
public Int32 PostId { get; set; }
public String LanguageCode { get; set; }
public IncludeExpression Include { get; set; }
}
所有参数获取值的唯一方法是:
已启用FromQuery
,所以我没有错误Unsupported Media Type
在Request类中具有FromRoute
来绑定PostId。
没有其他方法吗?
我尝试了以下操作,这对我来说是合理的,但不起作用:
[ApiController]
public class PostController : Controller
{
[HttpGet("posts/{postId:int:min(1)}")]
public async Task<IActionResult> GetByPostId([FromRoute, FromQuery]GetByPostIdRequest request)
{
}
}