.Net核心AJAX Post Null
我尝试了各种配置,但无法将数据传递到控制器。我错过了什么.Net核心AJAX Post Null,ajax,asp.net-core-mvc,Ajax,Asp.net Core Mvc,我尝试了各种配置,但无法将数据传递到控制器。我错过了什么 public class PartsImport { public string companyID { get; set; } public string partsCategoryID { get; set; } public string subCategoryID { get; set; } public string partNumber { get; set; } public stri
public class PartsImport
{
public string companyID { get; set; }
public string partsCategoryID { get; set; }
public string subCategoryID { get; set; }
public string partNumber { get; set; }
public string name { get; set; }
public string description { get; set; }
public string description2 { get; set; }
public string quantity { get; set; }
public string cost { get; set; }
public string price { get; set; }
public string vendorID { get; set; }
public string mfg { get; set; }
public string companyLocationID { get; set; }
}
控制器。此时partsImport为空
[Authorize(Roles = "Admin")]
[HttpPost]
public async Task<IActionResult> ImportPartsData([FromBody] IEnumerable<PartsImport> partsImport)
{
...
}
删除{“partsImport”:}
。按如下方式更改代码:
var data = [{ "companyID": "57", "partsCategoryID": "205", "subCategoryID": "", "partNumber": "1", "name": "PVC Conduit 1/2 inch by 10 Feet", "description": "1/2 inch", "description2": "", "quantity": "1", "cost": "2.40", "price": "3.10", "vendorID": "", "mfg": "", "companyLocationID": "156" },
{ "companyID": "57", "partsCategoryID": "205", "subCategoryID": "", "partNumber": "2", "name": "PVC Conduit 3/4 inch by 10 Feet", "description": "3/4 inch", "description2": "", "quantity": "1", "cost": "3.03", "price": "3.91", "vendorID": "", "mfg": "", "companyLocationID": "156" }
];
结果:
最简单的方法是删除
“partsImport”:
我想。
var data = [{ "companyID": "57", "partsCategoryID": "205", "subCategoryID": "", "partNumber": "1", "name": "PVC Conduit 1/2 inch by 10 Feet", "description": "1/2 inch", "description2": "", "quantity": "1", "cost": "2.40", "price": "3.10", "vendorID": "", "mfg": "", "companyLocationID": "156" },
{ "companyID": "57", "partsCategoryID": "205", "subCategoryID": "", "partNumber": "2", "name": "PVC Conduit 3/4 inch by 10 Feet", "description": "3/4 inch", "description2": "", "quantity": "1", "cost": "3.03", "price": "3.91", "vendorID": "", "mfg": "", "companyLocationID": "156" }
];