`[FromQuery]`IEnumerable 在ASP.NET Core 3.1中解析?

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

因此,当我测试绑定对IEnumerable<string>参数的工作方式时,您只需反复在查询字符串中传递参数名称,就像这样:?a=item1&a=item2&a=item3...

所以,如果我有一个类型为IEnumerable<SimpleObject> a的参数,其中SimpleObject的定义如下,我该写些什么:

public class SimpleObject
{
   public string Number { get; set; }
   public string Text { get; set; }
}

为了成功将其绑定到所述对象列表?还是不存在该映射的默认ModelBinder? ((在这种情况下,请提供示例ModelBinder)

c# asp.net-core model-view-controller model-binding model-validation
1个回答
1
投票

默认的模型绑定设置支持索引格式,其中针对索引指定每个属性。最好通过示例查询字符串来演示:

© www.soinside.com 2019 - 2024. All rights reserved.