Get Nth item from SelectList
Asked Answered
S

1

6

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.

Subsistent answered 24/8, 2011 at 15:49 Comment(0)
C
12

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

Croy answered 24/8, 2011 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.