【发布时间】:2021-05-16 00:13:07
【问题描述】:
我的 API 无缘无故地变为 null。这是为什么呢?
[AllowAnonymous]
[HttpPost("category")]
public async Task<IActionResult> PostProductCategory([FromBody] ProductCategoryViewModel message)
型号:
public class ProductCategoryViewModel
{
public int? Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Advantages { get; set; }
public decimal? Liambda { get; set; }
public string Icon { get; set; }
public string UseCase { get; set; }
public string UseCaseTwo { get; set; }
public int? PackageType { get; set; }
}
我发送的json:
{
advantages: "",
description: "",
icon: "",
id: 0,
liambda: "1111",
name: "asdfas",
packageType: 1,
useCase: "",
useCaseTwo: ""
}
【问题讨论】:
-
那不是有效的 json
-
这怎么无效?
-
JSON 属性名称必须被引用。
-
好的解决了这个问题。被引用了,我只是从其他地方复制的。问题是当我在 JS 中输入数据时,我使用输入字段“文本”作为十进制?价值。这就是它不起作用的原因。