asp.net - Is it possible to Pass set of table records from front end to back end using MVC3 -
i'm displaying table in front end table records editable , each record has check box.
if records selected making corresponding checkboxes checked , submitted selected records have stored in backend table.
is possible using asp.net mvc3?
if yes how pass list of records view controller , model?
as understand want pass array of selected checkboxes actionresult during post. see example below
model:
public class editableitemmodel { public bool selecteditem { get; set; } public string name { get; set; } } controller:
public actionresult index() { var model = new editableitemmodel[] { new editableitemmodel { selecteditem = true }, new editableitemmodel() }; return view(model); } [httppost] public actionresult index(editableitemmodel[] tableitems) { ienumerable<editableitemmodel> selecteditems = tableitems.where(i => i.selecteditem); return redirecttoaction("index"); } view:
@using checkboxintableexample.models; @model editableitemmodel[] @using (html.beginform("index")) { <table> @for (int = 0; < model.length; i++) { <tr> <td> @html.checkboxfor(m => m[i].selecteditem) </td> <td> @html.editorfor(m => m[i].name) </td> </tr> } </table> <input type="submit" title="submit" /> } hope helps.
Comments
Post a Comment