开发者

No "Specified argument was out of the range of valid values" with DropDownListFor

开发者 https://www.devze.com 2023-01-13 05:08 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消