如何解决有关在 Guid 属性中传递空值的错误?

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

我正在尝试发布 JSON,因为它应该用作过滤器/搜索的请求主体,因此允许空值:

{
    "Guid":"",
    "FirstName":"",
    "LastName":""
}

而且,DTO类是:

Public class PersonDto
{
       public Guid Guid { get; set; }
       public string FirstName { get; set; }
       public string LastName { get; set; }
}

而且,我明白了

"Error converting value \"\" to type 'System.Guid'
,我试过将 Guid 保留为 Guid?但这也行不通

c# nullable guid
1个回答
1
投票

""
不是有效的指南。强类型对象总是可以为空的,所以你不需要
Guid?

您可以使用

null
或者您可以使用适当的 guid,但不能使用空字符串。

{
  Guid: null,
  FirstName: "Larry",
  LastName: "Jones"
}
© www.soinside.com 2019 - 2024. All rights reserved.