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

  • Home
  • SEARCH
  • 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 237763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:27:06+00:00 2026-05-11T20:27:06+00:00

Background: I have an ASP.NET MVC view page with a MultiSelectList in the View

  • 0

Background: I have an ASP.NET MVC view page with a MultiSelectList in the View Model. I want to populate a label with the list of SelectedValues from that MultiSelectList object. The list is stored within the MultiSelectList with a type of IDName:

public class IDName {
    public int ID {get; set;}
    public string Name {get; set;}
}

So MultiSelectList.Items is an IEnumerable containing a list of IDName’s. I can do a foreach over this list and grab .Name to get the name of each entry. But, I only want to do this if the ID is in MultiSelectList.SelectedItems, which appears to be a string[] and looks like:

["1", "3", "4"]

So, I want to just get the IDName.Name when IDName.ID is in the SelectedItems list.

I’m pretty new to both MVC and C# so I’m not sure the best way to do that. Any suggestions?

Update #2:

OK, I was being dense. This works:

list.Items
  .Cast<IDName>()
  .Where(x => list.SelectedValues.Cast<string>().Contains(x.ID.ToString()))

SelectedValues is actually an IEnumerable containing a string[].

  • 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-05-11T20:27:06+00:00Added an answer on May 11, 2026 at 8:27 pm

    Try the following.

    var selected = MultiSelectList.Items
      .Cast<IDName>()
      .Where(x => MultiSelectList.SelectedItems.Contains(x.Name));
    

    What this does is process all of the items in the MultiSelectList.Items collection. It will then cast all of them to a strongly typed IDName instance. The where clause will filter the collection to only the items where the Name field matches an entry in the SelectedItems array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 242k
  • Answers 242k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you have no control at all from the host,… May 13, 2026 at 7:32 am
  • Editorial Team
    Editorial Team added an answer You can try using the TraceView Tool. This tool is… May 13, 2026 at 7:32 am
  • Editorial Team
    Editorial Team added an answer To quote David West: The definition of inheritance then becomes,… May 13, 2026 at 7:32 am

Related Questions

I am developing an ASP .Net MVC application and on my dev machine, the
A little background: I'm a C# developer starting to mess with the iPhone (have
I'm trying to get an ASP.NET MVC app working... I should have known it
Background I'm receiving the following error when trying to render a partial view in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.