[英]How to pass List<object> via MultipartFormDataContent c#
我試圖了解如何使用 MultipartFormDataContent 進行 API 調用。 到目前為止,我已經能夠發送帶有字符串的變量和列表,但是每當我嘗試發送帶有整數的列表或帶有類的列表時,API 都會檢索到一個空列表。
我該如何發送?
這是我的有效代碼:
var multiForm = new MultipartFormDataContent();
var json = JsonConvert.SerializeObject(testClass.steps); //this is list of string with steps
multiForm.Add(new StringContent(testEmployee.UserID.ToString()), "UserID");
multiForm.Add(new StringContent(json), "steps");
那么如何發送整數列表或員工列表? 我試過像上面那樣做,但沒有用。 然后 API 檢索一個空列表。
var multiForm = new MultipartFormDataContent();
var json = JsonConvert.SerializeObject(testClass.steps); //this is list of string with steps
multiForm.Add(new StringContent(testEmployee.UserID.ToString()), "UserID");
multiForm.Add(new StringContent(json), "steps");
服務
[HttpPost("MyFunction")]
public IActionResult MyFunction([FromForm] string steps)
{
List<step> models= JsonConvert.DeserializeObject<List<step>>(steps);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.