.NET 7 从表单发送列表始终为空值

问题描述 投票:0回答:0

我试图从 swagger 和 Postman 发布一个类,但参数

Skills
Availabilities
总是收到 null。

public class ServicesRequest
    {
        public int? ServiceId { get; set; }
        public int UserId { get; set; }
        public int CategoryId { get; set; }
        public int? AddressId { get; set; }
        public int ServiceTypeId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public decimal Price { get; set; }
        public List<SkillRequest> Skills { get; set; }
        public List<AvailabilityRequest> Availabilities { get; set; }
        public IFormFileCollection ServicesImages { get; set; }
    }
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
    public class SkillRequest
    {
        public int? SkillId { get; set; }
        public string Name { get; set; }
    }
[HttpPost]
        [Route("")]
        [SwaggerResponse((int)HttpStatusCode.OK, Type = typeof(ServicesResponse))]
        [SwaggerResponse((int)HttpStatusCode.NotFound, Type = typeof(PertoErrorResponse))]
        public async Task<ActionResult<ServicesResponse>> UpsertServicesAsync([FromForm] ServicesRequest servicesRequest)
        

我尝试使用不同的消费 application/json、multipart、application/x-www-form-urlencoded,更改 [FromForm]、[FromBody]

c# .net httprequest
© www.soinside.com 2019 - 2024. All rights reserved.