I have a form which contains a series of fields like:
See http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx for the syntax necessary to bind to a dictionary. Note in particular the example of binding MSFT + AAPL company tickers around halfway down that post.
For ASP.NET MVC 2 use this:
<input type="hidden" name="User[0].Key" value="123" />
<input type="text" name="User[0].Value" value="Alice" />
<input type="hidden" name="User[1].Key" value="456" />
<input type="text" name="User[1].Value" value="Bob" />
You need an extra hidden field User[i].Key. i is zero-based index. It should be uninterrupted.
when you model bind to a dictionary, you're actually binding to an
ICollection<KeyValuePair<,>>
. So you need User[x].Key and User[x].Value (to reconstitute the KeyValuePair object)
References
It's possible for lists, I'm sure it carries over for dictionaries as well. Read through Model Binding to a List by Phil Haack for some understanding on how list binding works.
You should be able to do this:
<input type="hidden" name="User.Index" value="123" />
<input type="text" name="User[123]" value="Alice" />
<input type="hidden" name="User.Index" value="456" />
<input type="text" name="User[456]" value="Bob" />