c# - Submit Multiple Rows from Grid MVC -
i trying add multiple objects simple grid @ 1 go. followed article http://www.donnfelker.com/editable-grid-list-binding-in-mvc2/ missing thing cant figure out. in controller getting null items posted
view:
@model list<itemclass> @using (html.beginform("action", "controller", formmethod.post)) { <table> <thead> <th>propertya</th> <th>propertyb</th> </thead> @for (int = 0; < model.count; i++) { @(html.editorfor(m => model[i], "templatename")) } </table> <button type="submit" value="submit"></button> }
edit template single item:
@model itemclass <tr> <td> @html.editorfor(m => model.propertya) </td> <td> @html.editorfor(m => model.propertyb) </td> </tr>
controller:
[httppost] public actionresult createitems(list<itemclass> items) { //create in db return redirecttoaction("xxxxxx"); }
try [httppost] public actionresult createitems(list<itemclass> items) { // impelement loop parameter items varialbe store values // in database for(int i= 0 ; i<item.count; ++) { //implement insertion logice here. } return redirecttoaction("xxxxxx"); }
Comments
Post a Comment