如何处理/允许将空字符串用作List 的空值? ASP.NET Core ModelState验证中的属性?

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

ASP.NET Core 3.0(启用Nullability References的API控制器使用以下模型:

public class SampleModel
{
    public string Title { get; set; } = null!;

    public List<Guid>? Guids { get; set; }
}

由于某种原因,如果列表为空,则客户端将为Guids属性发送一个空字符串。这会将ModelState标记为invalid(表示空字符串不是有效值)。

如何允许空字符串并将其转换以将空列表或null值设置为Guids属性(我不在乎,选择哪个更容易)?

c# asp.net-core modelstate
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.