views:

18

answers:

1

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 have 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.

A: 

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.

dmonlord