【问题标题】:Why is my Post FromBody null in my API call?为什么我的 API 调用中的 Post FromBody 为空?
【发布时间】: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 中输入数据时,我使用输入字段“文本”作为十进制?价值。这就是它不起作用的原因。

标签: json api .net-core


【解决方案1】:

好的,问题已解决。被引用了,我只是从其他地方复制的。问题是当我在 JS 中输入数据时,我使用输入字段“文本”作为十进制?价值。这就是它不起作用的原因。

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 2014-10-13
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多