views:

23

answers:

1

I'm following Phil's great tutorial on model binding to a list.

I use input names like this:

book[5804].title
book[5804].author
book[1234].title
book[1234].author

This works well and the data gets back to the model just fine, populating a list of books.

What I'm looking for is a way to get access in the model to the index that was used to send the books. I'd like to get that number, "5804." This is because the index is of semantic importance. If I can access it, it saves me from setting another property on the object (book ID).

Is there a way to see, either on the FormCollection or on the model after UpdateModel is called, what the index was when it was sent up?

A: 

If the index has semantic importance put it into the model:

book[0].id = "5804"
book[0].title = "title 1"
book[0].author = "author 1"

book[1].id = "1234"
book[1].title = "title 2"
book[1].author = "author 2"
Darin Dimitrov
This would require me to put an additional hidden input field into the markup. I was hoping to avoid this. I see your point about including semantic fields in the model, and, in fact, I intend to populate ID once the FormCollection gets to the model. If I could read the index from the FormCollection, that would seem like an elegant way to solve this. Are you saying this isn't possible, Darin?
Simple As Could Be