Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8481943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:41:49+00:00 2026-06-10T19:41:49+00:00

I have a SelectList that looks like. . . new SelectList(new[] { new {

  • 0

I have a SelectList that looks like. . .

new SelectList(new[]
    {
        new { Value = "1", Text = "AK" },
        new { Value = "2", Text = "AL" },
        new { Value = "3", Text = "AR" },
        new { Value = "4", Text = "AZ" },
        etc. . . 

Given an int I need to be able to select the corresponding Value so I can return the associated Text. So if I have the int 3, I want to ultimately return the string “AR” — how do I do this?

I don’t seem to understand how SelectLists work, I’ve been trying something like:

var stringValue = mySelectList.Where(m => m.Value == myInt).Text;  

— This does not work for a couple of reasons:

  • .Text is not something I can put at the end of the request as it cannot be resolved
  • m.Value - myInt tells me I cannot convert the source type 'int' to target type 'string', and if I change the int to a string I get the error: cannot convert expression type 'string' to return type 'bool'.

I feel like I am overcomplicating something here. Where did I go wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:41:51+00:00Added an answer on June 10, 2026 at 7:41 pm

    You probably need something like this:

    var stringValue = mySelectList.Where(m => m.Value == myInt.ToString())
                                  .First()
                                  .Text; 
    
    • The Where method does not return a SelectListItem, it returns a query. You need to force the query to execute, and get the first result, by using the First() method.
    • You’re using = (assigning a value) instead of == (comparing two values).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdownlist that looks like this: @Html.DropDownListFor( x => x.Attribute.AttributeID, new SelectList(Model.Attributes,
I have the following code in a view: <div class=wrap_select> @Html.DropDownList(dateRange, new SelectList(Model.DateRange, Value,Text),
I have multiple dropdown list: @Html.DropDownListFor(x => x.HaveColoSpace.SelectedOptions, new SelectList(Model.HaveColoSpace.Options, Value, Text), new {
Hi I have this code in my view.. <%=Html.DropDownList(ProductTemplate,new SelectList(Model.ProductTemplate,Value,Text))%> I know if this
I have been asked to produce a select list that looks like this: The
So if I have a select list of lets say dates that looks like
I have a route that looks like this: new { controller = ControllerName, action
I have an Html Helper that converts an Enum into a SelectList like so:
I have a dropdown I am populating with data that looks like.... List<SelectListItem> items
If have a string passed from a .Net application that looks like the below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.