Number of items in a picklist (IEnumerable counter)

As you can see here and here I am not a good friend of asp.net MVC SelectList.
This time I wonder how to count the elements in it. I want to show a shortcut instead of a drop-down list if the possible elements do not offer any choice (items.count <2).

- EDIT -

Although the answer probably works too, the easy way to go is a challenge

.GetListItems().Count() 

This disables any lazy selections you have, but since they will still be in the drop down list, I don't think this should be a problem.

+6
asp.net-mvc
source share
2 answers

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

+4
source share

Linq does not have an extension method for IEnumerable called Count (). The Count () function is implemented for IEnumerable, which is a big difference.

+3
source share

All Articles