mvc model binding collections on forms, submit only changes?
i've seen how to do model binding with asp mvc using collections of objects on a form. how does one submit only changes, a subset of the collection objects, that got changed? (add, delete, change). override the submit with script and somehow roll it yourself ? (to make it easy, lets make the granularity of changes restricted to an object in the collection, ie not down to the object prop开发者_如何学JAVAerties).
Thanks
I'd consider dropping the form altogether and just focus on posting json back to the server. This will save you a lot of fiddling with input elements.
On the server side you can just bind to a list of the given object.
If you submit only changes, you will have to a. manually submit the form elements that have changed in either a manual jQuery call (either through submitting the data via jQuery via json or explicitly passing in the form values
$.post("/controller/action", { name1: "John", name2: "Mary" } );
its your design choice to use json or not here - both will work just fine. if you choose json, change your dataType in the call to json you use
dataType: 'json'
b. remove the unchanged elements from the form upon post and c. move the changed elements into their own form before post both b/c can use:
$.post("/controller/action", $("#changedForm").serialize());
精彩评论