Last post Feb 04, 2010 04:42 PM by levib
Feb 04, 2010 04:05 PM|shapper|LINK
On a strong typed model I have a property of type IDictionary<int, string>.
This is not used by the form ... only by a validation class after the form is submitted.
However, since it isn't in the form when it is submitted its value are lost.
My idea is to place this in a hidden input but how is the model updated?
I mean how is the model property going to get the IDictionary values after form submission?
Feb 04, 2010 04:42 PM|levib|LINK
If your model has a property SomeProperty of type IDictionary<int, string>, the binder can bind this. Make your hidden fields look like the following:
SomeProperty.key = 42
SomeProperty.value = forty-two
SomeProperty.key = 84
SomeProperty.value = eighty-four
(This is the list binding syntax, only it's a list of KeyValuePair<int, string>.)
However, consider what you're going to use this data for if not for something that will be typed in by the end user. Because it's part of the Form, it can be manipulated by the end user before being sent back to the server. If this isn't a concern or doesn't
matter, hidden form fields should work. If you need to be sure the data hasn't been manipulated by the end user, just set the dictionary manually from within the controller on POST.