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 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

Related Questions

Background I have a page on my ASP.NET MVC web app for users to
background:Me and my coworkers are working on asp.net mvc project ... we have a
First some brief background: I have an existing ASP.NET MVC 1 application using Entity
I have an ASP.NET MVC site (Master Page + Content pages). On the master
I have an ASP.NET MVC Page that has Left Menu navigation that is built
I am very new to asp.net mvc. I also have no enough background in
Technical Details C#, ASP.NET 4, MVC 3, SQL backend, ADO.NET (edmx) Background/Context I have
Background: I have a website (ASP.NET MVC) where users can write/edit/delete a review. Doing
I am new to ASP.NET MVC, coming from a web forms background in the
I come from an ASP.NET MVC background and am currently going through the following

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.