【发布时间】:2021-02-04 20:27:48
【问题描述】:
我正在尝试将数组传递给控制器以更新那些匹配的记录 这是我传递数组的方式:
[Route("api/updateFile/{id}")]
[HttpGet]
[HttpPost]
public void updateFile(int[] ids, string FolderName, Int Key)
{
var FilesToUpdate = db.ActivityFiles.FirstOrDefault(x => x.id == ids); //ids containing 124,52,22,262,32
FilesToUpdate.id= FolderName;
FilesToUpdate.Key = Key;
_db.SaveChanges();
}
Ajax 非常简单
$.ajax({url: '/api/updateFile/' + imgList + '?FolderName=' + 545454 + '&Key=' + 777,
type: "GET",success: function (data) {console.log("image set updated - success! ");},
error: function (data) {}});
imgList 包含:124,52,22,262,32
但这似乎永远行不通,有没有更好的方法来归档我要归档的内容?
【问题讨论】:
-
我不会做那样的网址。
-
您需要一个自定义模型绑定器。 Google for ArrayModelBinder,很确定有博客文章
-
@DanielA.White 是的,那是为了测试目的
标签: c# asp.net asp.net-web-api