【发布时间】:2020-10-09 19:35:03
【问题描述】:
我的设置
- Asp.Net Core 3.1 Web API
- 招摇用户界面
问题
这是请求对象的一部分
public class CreatePostRequest
{
public long? EventTime { get; set; }
public long? EndTime { get; set; }
public List<string>? Tags { get; set; }
}
在控制器中,我将它们作为一个字符串接收
这是控制器:
[HttpPost(ApiRoutes.Posts.Create)]
[ProducesResponseType(typeof(Response<CreatePostResponse>), 201)]
public async Task<IActionResult> Create([FromForm]CreatePostRequest postRequest)
{
// postRequest.Tags.Count == 1 -> both in the first list element separated by coma
}
我需要将它们作为 2 个单独的字符串接收。我认为问题可能出在模型绑定上,但不确定。 可能是什么问题?
【问题讨论】:
-
使用 [FromForm] 属性对您来说重要吗?我会尝试删除该属性并在控制器类上方添加 [ApiController] 。它将使您能够拥有标准的 Web API 绑定。
-
@klucyszy 好的,[ApiController] 没有帮助,我需要 [FromFrom] bc 我有一些 IFormFile 输入
-
我复制了你的问题。它看起来像 Swagger UI 中的一个错误。我使用 Postman 没有这个问题。
-
@klucyszy 是的,在邮递员中也为我工作。我想我会这样离开它。
标签: c# asp.net-mvc asp.net-core asp.net-core-webapi swagger-ui