FormData 绑定到 ASP.NET Core Web API

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

我正在开发一个应用程序,我应该在其中获得包含以下属性的 formData 响应。问题是我无法获取属性,并且 JSON 属性对我不起作用。

[AllowAnonymous]
[HttpPost("postResponse")]
public async Task<IActionResult> ValidatePaymentAsync([FromForm] PaymentResponseDto response)
{
    _logger.LogInformation ($"API Callback is working --- Response :{JsonConvert.SerializeObject(response)}");
    return Ok(await _resourceService.ValidatePaymentAsync(response));
}

public class PaymentResponseDto
{
    public string idSession { get; set; }
    public string statusPBX { get; set; }
    [JsonProperty("3DENROLLED")]
    public string _3DENROLLED { get; set; }
    public string id3D { get; set; }
    public string check { get; set; }
}

问题伴随着

3DENROLLED
。响应包含该值,但我没有得到它。数据成员也不适合我。

c# asp.net-core-webapi
1个回答
0
投票

您可以尝试将以下代码添加到program.cs:

builder.Services.AddControllers().AddNewtonsoftJson().ConfigureApiBehaviorOptions(o => {
    o.SuppressInferBindingSourcesForParameters = true;
});
© www.soinside.com 2019 - 2024. All rights reserved.