【问题标题】:.NET Core 3.1 API POST parameter is null.NET Core 3.1 API POST 参数为空
【发布时间】:2021-02-25 09:47:37
【问题描述】:

我用这个参数向服务器发送数据

但是在函数的参数中得到空值

如果我为输入函数设置数据类型dynamic,那么一切正常,我可以获取值。 报告类

public class ColumnHistory
{
    int ECH_COUNTER { get; set; }
    int TOTAL_WEIGHT { get; set; }
    int TOTAL_COUNT { get; set; }
    string COLUMNS_PLACE { get; set; }
   
}
public class InventoryInPlace
{
  
    int ELC_SIZE { get; set; }
    int STO_COUNT { get; set; }
    int STO_WGT { get; set; }
    int STO_COUNTER { get; set; }
    string ELC_ID { get; set; }

}
public class Report
{
    public ColumnHistory[] columnHistory { get; set; }
    public InventoryInPlace[] inventoryInPlace { get; set; } 
}

【问题讨论】:

  • 代码图片不是minimal reproducible example
  • 请分享Report类的代码
  • @PeterCsala 报告类代码添加
  • 能否请您将参数类型更改为string 以查看接收到的有效载荷。或者您可以通过string rawRequest = await Request.Content.ReadAsStringAsync(); 捕获它吗?请将其作为代码包含在问题中。

标签: c# asp.net-core asp.net-core-3.1


【解决方案1】:

如果不声明访问修饰符,则类成员的访问级别默认为private。请务必为以下属性添加访问修饰符:

public class ColumnHistory
{
    public int ECH_COUNTER { get; set; }
    public int TOTAL_WEIGHT { get; set; }
    public int TOTAL_COUNT { get; set; }
    public string COLUMNS_PLACE { get; set; }

}
public class InventoryInPlace
{

    public int ELC_SIZE { get; set; }
    public int STO_COUNT { get; set; }
    public int STO_WGT { get; set; }
    public int STO_COUNTER { get; set; }
    public string ELC_ID { get; set; }

}

【讨论】:

    猜你喜欢
    • 2017-08-28
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 2017-06-07
    • 2021-01-26
    • 2018-01-24
    • 2021-04-24
    • 1970-01-01
    相关资源
    最近更新 更多