Html:
@using (Html.BeginForm("Edit", "Home"))
{
<div>
<input type="submit" value="保存" class="delete" />
</div>
<table>
<tr>
<th>@Html.CheckBox("chackall")</th>
<th>名称</th>
<th>排序号</th>
<th>操作</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td><input name="id" value="@item.id" type="hidden" /></td>
<td><input name="name" value="@item.Name" type="text" /></td>
<td><input name="sortid" value="@item.SortId" type="text" /></td>
<td>@Html.ActionLink("详细", "Details", new { id = "" })</td>
</tr>
}
</table>
}
Action:
[HttpPost]
public ActionResult Edit(List<int> id, List<string> name, List<int> sortid)
{
ApplicationContext db = new ApplicationContext();
try
{
for (int i = ; i < id.Count(); i++)
{
var K = db.Categories.Where(m => m.id == id[i]).First();
K.Name = name[i];
K.SortId = sortid[i];
}
db.SaveChanges(); return RedirectToAction("Index");
}
catch
{
return View();
}
}
运行效果: