我有一个嵌套的模型.当我使用Postman发出POST请求时,我可以获得除嵌套的File属性之外的所有属性.为什么只有嵌套文件属性为空?解决方案是什么? 请求的嵌套模型和屏幕截图如下:

public class RequestDTO
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IFormFile Image { get; set; }
    public TestModel Test { get; set; }
}

public class TestModel
{
    public string Desc { get; set; }
    public IFormFile File { get; set; }
}

enter image description here enter image description here

推荐答案

使用Test.file而不是Test[file].

curl --location --request POST 'https://localhost:7212/weatherforecast' \
--form 'id="1212"' \
--form 'name="qweqweqw"' \
--form 'image=@"/<Folder-path>/sun-flower-transparent-background-additional-png-file-greeting-cards-holiday-wishes-sun-flower-transparent-129371261.jpg"' \
--form 'Test[desc]="csdds"' \
--form 'Test.file=@"/<Folder-path>/Fruit-PNG.png"'

演示

enter image description here

Csharp相关问答推荐

CsWin32如何创建PWSTR的实例,例如GetWindowText

为什么Blazor值在更改后没有立即呈现?

无法解析数据库上下文的服务

选取器与.NET Maui MVVM的绑定属性

HttpConext.Request.Path和HttpConext.GetEndpoint()之间的差异

Amazon SP-API确认发货不设置&Quot;递送服务

在调整大小的控件上绘制

C#无法让WinForm进度条生成动画错误跨线程操作无效

从另一个不同 struct 的数组创建Newtonsoft.Json.Linq.J数组

如何在CSharp中将json字符串转换为DataTable?

如何允许数组接受多个类型?

我可以查看我们向应用程序洞察发送了多少数据吗?

使用动态键从请求体反序列化JSON

如何让游戏对象在切换场景时被销毁,但在开始新游戏时重新锁定

获取混淆&Quot;模糊引用&Quot;错误

用MongoDB c#驱动程序删除和返回嵌套数组中的文档

从MudAutoComplete打开对话框,列表仍然可见

如何对构建在Clean架构和CQRS之上的控制器进行单元测试?

Unity 3D-意外轴捕捉和未知力对脉冲react 行为的影响

无法创建工具窗口(用于VBIDE、VBA的COM加载项扩展)