ASP.. NET MVC更新多行Postgresql



我试图在一个视图中更新多行到Postgresql。下面的代码只更新第一行,有解决方案吗?

private readonly AppDbContext appDbContext;
public EmployeeRepository(AppDbContext db)
{
db = appDbContext;
}
[HttpGet]
public ActionResult Index()
{
model = db.Contacts.ToList();
return View(model);
}
[HttpPost]
public ActionResult Index(List<Contact> list)
{ 
foreach (var i in list)
{
var c = db.Contacts.Where(a => a.ContactID.Equals(i.ContactID)).FirstOrDefault();
if (c != null)
{
c.ContactPerson = i.ContactPerson;
c.Contactno = i.Contactno;
c.EmailID = i.EmailID;
}
}
dc.SaveChanges();
return View(list);
}

视图

@model List<UpdateMultiRecord.Contact>
@using (@Html.BeginForm("Index","Home", FormMethod.Post))
{
<table>
<tr>
<th></th>               
<th>Contact Person</th>
<th>Contact No</th>
<th>Email ID</th>
</tr>
@for (int i = 0; i < Model.Count; i++)
{
<tr>               
<td> @Html.HiddenFor(model => model[i].ContactID)</td>
<td>@Html.EditorFor(model => model[i].ContactPerson)</td>
<td>@Html.EditorFor(model => model[i].Contactno)</td>
<td>@Html.EditorFor(model => model[i].EmailID)</td>
</tr>
}
</table>
<p><input type="submit" value="Save" /></p>

}
@section Scripts{
@Scripts.Render("~/bundles/jqueryval")
}

我想在一个视图中编辑许多行(如100)并将数据保存到postgresql,也许有人有任何其他想法?

您尝试过更新for循环中的上下文吗?