다양한 구성을 시도했지만 컨트롤러에 전달할 데이터를 가져올 수 없습니다. 내가 무엇을 놓치고 있습니까?
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는 null입니다.
[Authorize(Roles = "Admin")]
[HttpPost]
public async Task<IActionResult> ImportPartsData([FromBody] IEnumerable<PartsImport> partsImport)
{
...
}
다음은 샘플 json 데이터와 함께 ajax 요청입니다. 두 버전을 모두 제출하려고 시도했지만 컨트롤러에 도달하면 계속 null을 얻습니다.
var data = { "partsImport": [{ "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" }] };
//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" }] ;
$.ajax({
url: "/purchasing/ImportPartsData",
type: "POST",
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (response) {
},
error: function (xhr, errorType, exception) {
},
});
제거 {"partsImport":}
아래와 같이 .Change에게 코드를 :
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" }
];
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다