ASP.NET MVC: Using EditorFor in a loop - ModelBinding to a single entity -
i think may little confused :-\
i have basic scenario whereby need render out list of forms. have basic viewmodel contains collection of entities. have editorfor template entity in question renders basic set of inputs. looks follows:
@for (var = 0; < model.count(); i++) { using (html.beginform("update", "vehiclelog", new { id = model[i].id }, formmethod.post, new { @class = "vehicle-update-form std-form", data_ajaxpost = "true", data_refreshcontainer = "#vehicle-ajax-holder" })) { @html.editorfor(model => model[i]) <div class="buttons right"> <input type="submit" value="save" name="action" class="btn-ok btn" /> <input type="submit" value="delete" name="action" class="btn-warning btn" /> </div> } } i have loop dumps out these editor template. far good. issue wish use updatemodel in post action update entity. however, data being sent controller takes following format:
my incomplete action looks follows:
[httppost] public actionresult update(int id, formcollection data, string action) { var response = new jsonresponse(); if (action == "update") { var v = unitofwork.vehiclerepository.getbyid(id); updatemodel(v); } return json(response); } my issue editorfor helpers (and rightly so) prefixing names array indexes, eg [0].name. such unable use updatemodel method update entity.
any advice appreciated!
Comments
Post a Comment