Model Binding to a List using non-sequential indexes. Can I access the index later?
Posted
by Kid A
on Stack Overflow
See other posts from Stack Overflow
or by Kid A
Published on 2010-06-16T21:16:50Z
Indexed on
2010/06/17
7:03 UTC
Read the original article
Hit count: 311
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?
© Stack Overflow or respective owner