c# mvc Controller中无法接收list类型的数据

后端Controller中接收方法如下:

[HttpPost]

public HttpResponseMessage BatchDoDistribute([FromBody]List<DistributeMaterial> list){

}

通过postman测试后发现,list能够接收到两个对象,但是对象的具体属性值却一个都没有接收到。如下图:
图片描述

使用postman进行post接口测试,数据格式是:application/json,测试数据如下:

[{

"StageName": "测试名称1",

"ContainerID": "999",

"ContainerTypeCode": "999",

"ProduceOrderNO": "WH18060041",

"OriginMaterialCode": "120400000009",

"LastModifyPerson": "自动登录用户",

"Location": "Cell-2-05-02",

"MaterialInventoryCode": "120400000009",

"IsSubstitutie": 0,

"TotalNeedDistribute": 66.0,

"ContainerCapacity": 20.0,

"Quantity": 66.0,

"ID": 0,

"IsDispatch": 0,

"ProduceLineStationID": 0,

"ProduceLineID": 0,

"WorkstageID": 24

},{

"StageName": "测试名称2",

"ContainerID": "999",

"ContainerTypeCode": "999",

"ProduceOrderNO": "WH18060041",

"OriginMaterialCode": "120400000009",

"LastModifyPerson": "自动登录用户",

"Location": "Cell-2-05-02",

"MaterialInventoryCode": "120400000009",

"IsSubstitutie": 0,

"TotalNeedDistribute": 66.0,

"ContainerCapacity": 20.0,

"Quantity": 66.0,

"ID": 0,

"IsDispatch": 0,

"ProduceLineStationID": 0,

"ProduceLineID": 0,

"WorkstageID": 24

}]

请问如何才能接收到呢?

回答:

字段名称不一致导致的吧?

回答:

[Serializable]

public partial class ME_DistributeMaterial

{

public ME_DistributeMaterial()

{ }

#region Model

private int _id;

private string _materialinventorycode;

private string _containertypecode;

private string _containerid;

//private decimal _quantity;//我自己修改成了public decimal Quantity{get; set;},可是还是接收不到

private string _produceorderno;

private int _workstageid;

private string _productinventorycode;

private int _producelinestationid;

private int _producelineid;

private int _isdispatch;

private DateTime? _dispatchtime;

private string _lastmodifyperson;

private DateTime _lastmodifytime;

private string _location;

private string _distributematerialbarcode;

private int? _issubstitutie;

private string _originmaterialcode;

public int ID

{

set { _id = value; }

get { return _id; }

}

public string MaterialInventoryCode

{

set { _materialinventorycode = value; }

get { return _materialinventorycode; }

}

public string ContainerTypeCode

{

set { _containertypecode = value; }

get { return _containertypecode; }

}

public string ContainerID

{

set { _containerid = value; }

get { return _containerid; }

}

public decimal Quantity{get;set;}

//{

// set { _quantity = value; }

// get { return _quantity; }

//}

public string ProduceOrderNo

{

set { _produceorderno = value; }

get { return _produceorderno; }

}

public int WorkstageID

{

set { _workstageid = value; }

get { return _workstageid; }

}

public string ProductInventoryCode

{

set { _productinventorycode = value; }

get { return _productinventorycode; }

}

public int ProduceLineStationID

{

set { _producelinestationid = value; }

get { return _producelinestationid; }

}

public int ProduceLineID

{

set { _producelineid = value; }

get { return _producelineid; }

}

public int IsDispatch

{

set { _isdispatch = value; }

get { return _isdispatch; }

}

public DateTime? DispatchTime

{

set { _dispatchtime = value; }

get { return _dispatchtime; }

}

public string LastModifyPerson

{

set { _lastmodifyperson = value; }

get { return _lastmodifyperson; }

}

public DateTime LastModifyTime

{

set { _lastmodifytime = value; }

get { return _lastmodifytime; }

}

public string Location

{

set { _location = value; }

get { return _location; }

}

public string DistributeMaterialBarcode

{

set { _distributematerialbarcode = value; }

get { return _distributematerialbarcode; }

}

public int? IsSubstitutie

{

set { _issubstitutie = value; }

get { return _issubstitutie; }

}

public string OriginMaterialCode

{

set { _originmaterialcode = value; }

get { return _originmaterialcode; }

}

#endregion Model

#region Extend

public string ProductInvName { get; set; }

public string LineName { get; set; }

public string StageName { get; set; }

public decimal ContainerCapacity { get; set; }

public decimal TotalNeedDistribute { get; set; }

#endregion

#region ExtendMethod

public static ME_DistributeMaterial Construct(System.Data.DataRow row)

{

if (row == null)

return null;

try

{

Tracker.Model.ME_DistributeMaterial model = new Tracker.Model.ME_DistributeMaterial();

if (row["ID"] != null && row["ID"].ToString() != "")

{

model.ID = int.Parse(row["ID"].ToString());

}

if (row["MaterialInventoryCode"] != null)

{

model.MaterialInventoryCode = row["MaterialInventoryCode"].ToString();

}

if (row["ContainerTypeCode"] != null)

{

model.ContainerTypeCode = row["ContainerTypeCode"].ToString();

}

if (row["ContainerID"] != null)

{

model.ContainerID = row["ContainerID"].ToString();

}

if (row["Quantity"] != null && row["Quantity"].ToString() != "")

{

model.Quantity = decimal.Parse(row["Quantity"].ToString());

}

if (row["ProduceOrderNo"] != null)

{

model.ProduceOrderNo = row["ProduceOrderNo"].ToString();

}

if (row["WorkstageID"] != null && row["WorkstageID"].ToString() != "")

{

model.WorkstageID = int.Parse(row["WorkstageID"].ToString());

}

if (row["ProductInventoryCode"] != null)

{

model.ProductInventoryCode = row["ProductInventoryCode"].ToString();

}

if (row["ProduceLineStationID"] != null && row["ProduceLineStationID"].ToString() != "")

{

model.ProduceLineStationID = int.Parse(row["ProduceLineStationID"].ToString());

}

if (row["ProduceLineID"] != null && row["ProduceLineID"].ToString() != "")

{

model.ProduceLineID = int.Parse(row["ProduceLineID"].ToString());

}

if (row["IsDispatch"] != null && row["IsDispatch"].ToString() != "")

{

model.IsDispatch = int.Parse(row["IsDispatch"].ToString());

}

if (row["DispatchTime"] != null && row["DispatchTime"].ToString() != "")

{

model.DispatchTime = DateTime.Parse(row["DispatchTime"].ToString());

}

if (row["LastModifyPerson"] != null)

{

model.LastModifyPerson = row["LastModifyPerson"].ToString();

}

if (row["LastModifyTime"] != null && row["LastModifyTime"].ToString() != "")

{

model.LastModifyTime = DateTime.Parse(row["LastModifyTime"].ToString());

}

if (row["DistributeMaterialBarcode"] != null)

{

model.DistributeMaterialBarcode = row["DistributeMaterialBarcode"].ToString();

}

if (row["LineName"] != null)

{

model.LineName = row["LineName"].ToString();

}

if (row["TypeName"] != null)

{

model.ProductInvName = row["TypeName"].ToString();

}

if (row["StageName"] != null)

{

model.StageName = row["StageName"].ToString();

}

return model;

}

catch (System.Exception ex)

{

// Log

Console.WriteLine(ex.Message);

}

return null;

}

#endregion

}

以上是 c# mvc Controller中无法接收list类型的数据 的全部内容, 来源链接: utcz.com/p/190372.html

回到顶部