【发布时间】:2022-01-02 02:40:06
【问题描述】:
例如,我有这段代码,它将数据发送到 asp.net core 6 web api 控制器。
const formData = new FormData();
formData.append("Id", 1);
formData.append("PhotoNames", ["name1", "name2", "name3"]);
formData.append("Photos", [file1, file2, file3)];
axios.post("/api/MyController", formData);
file1, file2, file3 是我从<input type="file"/> 收到的照片。
我通过在MyController.cs 中使用此代码处理了相同的请求,但没有数组:
public class Item
{
public int Id { get; set; }
public string PhotoName{ get; set; }
public IFormFile Photo { get; set; }
}
[HttpPost]
public IActionResult Post([FromForm] ImageModel file)
{
//Using all the data from the request here
}
请求看起来像:
const formData = new FormData();
formData.append("Id", 1);
formData.append("PhotoName", "name1");
formData.append("Photo", file1);
axios.post("/api/MyController", formData);
如何处理包含数组的发布请求?我需要在MyController.cs中使用什么样的类和函数?
【问题讨论】:
标签: javascript c# arrays asp.net-core axios