Search code examples
linqc#-4.0ienumerableselectlistselectlistitem

Get Nth item from SelectList


I'm trying to unit test a function which returns a SelectList.

How can I retrieve an item from the SelectList to verify that my model is being constructed correctly?

mySelectList.Items.First().DataValue

or whatever.


Solution

  • Simply use mySelectList.ElementAt(n) to get the nth SelectListItem.