Is it possibly to bind IDictionary using lambdas?
My answer is can I anyhow bind an IDictionary property using lambda expressions as it done in MVC 2 for simple properties?
I know how to bind IDictionary using old MVC notation via string property paths. But all the rest of model properties throughout all application operate using new MVC 2 approach, via lambda expressions. And therefore I extremely would not like apply old manner of model binding.
I saw also an article Model Bi开发者_如何学运维nding To A List posted by Phil Haack in his blog. But in that article Phil shows how to do binding using lambdas just for Lists, not for Dicrionaries. I tried to do similar with Dictionary typed properties, but DefaultModelBinder does not recognize them.
Example:
binding is:
<%= Html.TextBoxFor(model => model.DictionaryProperty[key].Title)%>
rendered html is:
<input id="DictionaryProperty_one__Title" name="DictionaryProperty[one].Title" type="text" value="" />
I would be appeciated for any helpful advices.
UPD: A index for dictionary property mentioned above was specified, of course:
view:
<%= Html.Hidden("DictionaryProperty.index",key)%>
rendered html:
<input id="DictionaryProperty_index" name="DictionaryProperty.index" type="hidden" value="one" />
You probably need something like OrderedDictionary class for your DictionaryProperty
http://msdn.microsoft.com/en-us/library/system.collections.specialized.ordereddictionary.aspx
精彩评论