C# ActionResult返回时缺少Null属性
我的控制器操作方法如下所示:C# ActionResult返回时缺少Null属性,c#,json,asp.net-core,asp.net-core-webapi,C#,Json,Asp.net Core,Asp.net Core Webapi,我的控制器操作方法如下所示: public virtual async Task<ActionResult<Customer>> GetCustomerAddress(int CustomerId) { customer = await scope.ServiceProvider .GetRequiredService<CustomerClient>()
public virtual async Task<ActionResult<Customer>> GetCustomerAddress(int CustomerId)
{
customer = await scope.ServiceProvider
.GetRequiredService<CustomerClient>()
.GetCustomerAddressAsyn(CustomerId);
Ok(Customer);
}
存储在此变量中时,CustomerMiddleName
值为空
Customer customer = await scope.ServiceProvider
.GetRequiredService<CustomerClient>()
.GetCustomerAddressAsyn(CustomerId);
postman测试的Json响应中缺少
CustomerMiddleName
属性本身。无法理解为什么会发生这种情况。当由OkObjectResult
返回时,此处缺少空值属性。可能您已在服务集合中将此值设置为trueoptions.JsonSerializerOptions.IgnoreNullValues=false代码>你能分享你的startup.cs代码吗?您似乎有一些特殊设置,如@TheGeneral所说,这些设置会忽略空值。不要使用此设置options.JsonSerializerOptions.IgnoreNullValues=false代码>任何地方。
Customer customer = await scope.ServiceProvider
.GetRequiredService<CustomerClient>()
.GetCustomerAddressAsyn(CustomerId);
return Ok(Customer);