【发布时间】:2019-03-28 22:28:24
【问题描述】:
我有一个 GET 请求 API 端点,它接收一个带有 Nullable 属性的请求视图模型,如下所示:
public class ModelRequestVM : BaseRequestVM
{
#region Properties and Data Members
public uint ModelId { get; set; }
public uint? MakeId { get; set; }
public string MakeName { get; set; }
public string ModelName { get; set; }
public uint? ExternalModelId { get; set; }
#endregion
}
但是当我使用 null 值对 MakeId 发出 get 请求时,API 不接受此可空类型的 null 值。
这是我的获取请求:https://localhost:44311/api/model/getlist?MakeId=null
我收到以下错误:
The value 'null' is not valid for MakeId.
【问题讨论】:
-
如果你完全省略它不会收到 null 吗?
-
@AFriend 我实际上希望它获得一些价值,基于它我可以获得所有模型。?
标签: c# asp.net-core asp.net-core-webapi