[HttpPost("add-car")]
public async Task<IActionResult> AddCarAsync([FromBody] AddCarInputDtos addCarInputDtos)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
}
public class AddCarInputDtos
{
public int? CodeParent { get; set; }
Required(ErrorMessage = "CodeCarList parameter is mandatory.")]
public int? CodeCarList { get; set; }}
[EnumDataType(typeof(YesNoEnum), ErrorMessage = "YesNoEnum value doesn't exist within enum")]
public YesNoEnum? FeatureLoad { get; set; }
}
当我用application / json格式的邮递员调用此API方法并跟踪代码对象为null时,它返回:
{
"$.featureLoad": [
"The JSON value could not be converted to System.Nullable`1[Jinavat.Backend.Api.Dtos.General.YesNoEnum]. Path: $.featureLoad | LineNumber: 0 | BytePositionInLine: 268."
]
}
请帮助我解决此问题。
答案 0 :(得分:1)
尝试在ConfigureServices中显式添加NewtonsoftJson:
catch(MyException ex)