When ypu send model 2 edited by the user via ajax...indexes must be considered part of it. So when your ajax call return back results, and new html is created, some old Html must be deleted too. Among the old Html to be deleted there are also the indexes...They
must be substituted to conform to the new model 2. In fact now deleted rows ghas already been taken into account and the model has been compacted...so the olde indexes that are still referring to the rows that have been deleted must be substituted.
So you don't have to line up with previous indexes, but just to substituthe them when the call return. How? With exactly the same code you used to create them the first time!
That said, I personally don't like toomuch the technique of the indexes used to handle list deletions, because the mapping that they define is based on their position in the html tree, so one must pay a lot of attention in avoiding to change their order
when manipulating the Html. In fact exchanging the position of two indexes in the page would cause the associated rows to be exchanged when the page is posted. However, the only other option is writing a custom model binder in an not easy way.
Once you have solved your problem...start considering what to doin case of errors. Errors handling is quite difficult when dynamic structures are involved if you need to process the whole user input into an unique transaction....You need to "rememer" the
whole set of changes done by the user while asking himto correct his errors, so once errors are corrected you can pass all changes together into an unique transaction.
I see what your saying, however at present I am not removing the first list which are being submitted with ajax, as they are build in a different area, and form part of the overall model, i was hoping just to link them up without a problem, and the only issue
is the indexing.
I could replace it, but I would need to rethink the sructure of my page, as its complicated enough at the moment, but will look into it.
If you don't like indexs in list definitions, how would you recommend I deal with them?
I have worked hard to make sure the ajax is strongly type and the unobrusive form validation works for the dynamic content, I will work some additional features in to refine it after, the thing I am having trouble with is ensureing that there are no database
errors making sure the records we are updating do belong to the model and haven't been altered manually.
EnenDaveyBoy
Participant
1465 Points
1147 Posts
Re: Model Binding to non sequencial list issue
May 02, 2012 05:14 PM|LINK
I could replace it, but I would need to rethink the sructure of my page, as its complicated enough at the moment, but will look into it.
If you don't like indexs in list definitions, how would you recommend I deal with them?
I have worked hard to make sure the ajax is strongly type and the unobrusive form validation works for the dynamic content, I will work some additional features in to refine it after, the thing I am having trouble with is ensureing that there are no database errors making sure the records we are updating do belong to the model and haven't been altered manually.