[英]Object is NULL when passed to Web API in .NET C#
將對象值傳遞到Web API時遇到問題。 我正在使用Anuglar5傳遞價值
{
"Company_User_Process_ID": 68,
"BankName": "1860 UBL , ABBOTTABAD",
"ChallanNo": "",
"AccountTitle": "",
"AccountNo": "",
"CompanyName": "sdasd",
"RegistrationNo": "",
"ProcessId": 1,
"PaymentType": false,
"Document_Pid": "",
"HeadsOfAccount": []
}
但是我越來越Null
。 我從“ 答案”中獲得了一些幫助。 但是我觀察到我傳遞的對象與通過額外的{}
進入Web API並不相同
{
{
"Company_User_Process_ID": 68,
"BankName": "1860 UBL , ABBOTTABAD",
"ChallanNo": "",
"AccountTitle": "",
"AccountNo": "",
"CompanyName": "sdasd",
"RegistrationNo": "",
"ProcessId": 1,
"PaymentType": false,
"Document_Pid": "",
"HeadsOfAccount": []
}
}
這是Web API的代碼
public async Task<ResponseObject<ChallanDetailViewModel>> CreateChallanDetail(ChallanDetailViewModel model)
{
...... My code here
}
這是模型類
public class ChallanDetailViewModel
{
public long Company_User_Process_ID { get; set; }
public string BankName { get; set; }
public string ChallanNo { get; set; }
public string AccountTitle { get; set; }
public string AccountNo { get; set; }
public string CompanyName { get; set; }
public string RegistrationNo { get; set; }
public int ProcessId { get; set; }
public int PaymentType { get; set; }
public string Document_Pid { get; set; }
public List<String> HeadsOfAccount { get; set; }
}
正在傳遞對象的客戶端代碼
this.http.post(url, model).map((response: any) => { return
response.json() }).toPromise();
我不確定是否適合您。 在將nested child list/collection
傳遞給API時,模型應在構造函數中初始化列表,如下所示,以便其選擇綁定:
public class ChallanDetailViewModel
{
public ChallanDetailViewModel()
{
HeadsOfAccount = new List<string>();
}
//Other properties
public List<String> HeadsOfAccount { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.