views:

65

answers:

1

Many of you may have noticed that since RC1 you don't have to include the .Index hidden field to enable complex model binding. However one of the drawbacks is that now you have to have the index starting from 0 and it cannot break. eg. skip from 4 to 6 etc.

With the old syntax I was able to just remove the item from the DOM and when the form submitted, all items except for the deleted one were posted. However with the new syntax if I remove index 5 then only 0-4 will be posted, because the index has broken.

How do you handle deleting an item from a list now?

A: 

Yes, the 'unbroken index' thing is a nuisance! There are 2 ways I have handled this in my projects:

The first way is by making the delete method on the client replace the whole list with fresh html from the server. This is fine for small lists and it's 'easy' as the index sequence is regenerated on the server.

With bigger lists that's not efficient though and in that situation I prefer to reorder the indexes with jquery on the client.

Steve Willcock