views:

1024

answers:

1

As you can see here and here I'm not a good friend of asp.net MVC's SelectList.
This time I'm wondering how to count the items in it. I want to show a label instead of a dropdown if the possible items don't offer any choice (items.count <2).

--EDIT--

Although Will's answer probably works too, the easy way to go is call

.GetListItems().Count()

This disables any lazy fetching you would have, but since they're gonna be in a dropdown anyway, I don't think that should be a problem.

+1  A: 

Linq has an extension method for IEnumerable called Count().

Will