0

I'm trying to post back a form with an enumerable number of items. When I have a list of elements with name = item[0].StartDate, name = item[1].StartDate, name = item[3].StartDate, etc. everything binds fine to an IEnumerable<Item> items property. However, let's say the user removes the first element or the middle element, then the binding no longer works because the items element is null in the former case and only the first item binds in the latter case.

Would I have to rename all the name attributes in the DOM if I'm deleting an element? Or is there a behind the scenes way I can tell ASP MVC to create the items object and start binding anything with the pattern item[i].StartDate?

uioporqwerty
  • 317
  • 5
  • 22
  • Indexers must be zero based and consecutive unless you include a form control for the indexer value - refer the answers [here](http://stackoverflow.com/questions/29161481/post-a-form-array-without-successful/29161796#29161796) and [here](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308) for examples –  Feb 28 '16 at 10:10
  • I think instead of hacking away at the indexor properties the nicer solution would be to just have an "IsDeleted" boolean property on your `Item`, exclude the ones set to `true` in your view and then ignore them at the server level as well. That way you still maintain the index. – Mathew Thompson Feb 28 '16 at 11:37

0 Answers0