我有这个API
public actionResult AddDocument([FromBody]AddDocumentRequestModel documentRequestModel)
{
AddDocumentStatus documentState = _documentService.AddDocument(documentRequestModel,DocumentType.OutgoingPosShipment);
if (documentState.IsSuccess)
return Ok();
return BadRequest();
}
这是我的请求模型
public class AddDocumentRequestModel
{
public AddDocumentRequestModel(int partnerId,List<ProductRequestModel> products)
{
PartnerId = partnerId;
Products = products;
}
[Range(1,int.MaxValue,ErrorMessage = "Value for {0} must be between {1} and {2}.")]
public int PartnerId { get; private set; }
[Required,MustHaveoneElement(ErrorMessage = "At least one product is required")]
public List<ProductRequestModel> Products { get; private set; }
}
所以当我尝试使用此主体来访问API
{
"partnerId": 101,"products": [{
"productId": 100,"unitOfMeasureId": 102,"quantity":5
}
]
}
这是请求:System.NotSupportedException:不支持无参数构造函数的引用类型的反序列化。键入“ Alati.Commerce.Sync.Api.Controllers.AddDocumentRequestModel”
我不需要无参数的构造函数,因为它不读取主体参数。还有其他反序列化的方法吗?