Html:
@using (Html.BeginForm ("Edit","Home")){ <div> <input type="Submit"Value="Save" class="Delete"/> </div> <table> <tr> <th> @Html. CheckBox ("Chackall") </th> <th> name </th> <th> sort numbers </th> <th> actions </th> </tr>@foreach (varIteminchModel) { <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 ("Detail","Details",New{id ="1"}) </td> </tr> } </table>}
Action:
[HttpPost] PublicActionResult Edit (list<int> ID, list<string> Name, list<int>SortID) {ApplicationContext db=NewApplicationContext (); Try { for(inti =0; I < ID. Count (); i++) { varK = db. Categories.where (m = m.id = =Id[i]). First (); K.name=Name[i]; K.sortid=Sortid[i]; } db. SaveChanges (); returnRedirecttoaction ("Index"); } Catch { returnView (); } }
Operating effect:
MVC4 Implementing batch Update data