No "Specified argument was out of the range of valid values" with DropDownListFor
In one of my views I want to output a textbox:
Html.TextBoxFor(x=>x.Foo[0].Bar) %>
This gives me the error "Specified argument was out of the range of valid values" if Model.Foo is empty.
I h开发者_如何转开发ave tried this with same model but with a drop down list instead:
Html.DropDownListFor(x=>x.Foo[0].Bar, Model.BarList) %>
No error...
This is not really a problem, but I think it is a strange behavior and I hope someone here can give me an explanation for it.
It's probably due to a reason that EditorFor<> syntax trys to make a ID and a name out of a property provided in x => x...And they probaly didn't anticipate that someone would use x.Foo[0].Bar in it, but as I can remember they did anticipate that x.Foo.Bar could work.
精彩评论