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 8451887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:21:42+00:00 2026-06-10T11:21:42+00:00

does anyone know how to initialise a MultiSelectList as empty? I have a ListBoxFor

  • 0

does anyone know how to initialise a MultiSelectList as empty?

I have a ListBoxFor control (MVC3) which i wish the user to populate by using other text and button controls on the web page.

It doesn’t like me commenting out the line below….

many thanks in advance

Items = new MultiSelectList(
    new[] 
    {
        //new { Id = 1, Name = "item 1" }                        
    },
    "Id",
    "Name",
    selectedItemIds
)
  • 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-10T11:21:44+00:00Added an answer on June 10, 2026 at 11:21 am

    When you create a MultiSelectList like that, one of the things the compiler checks is if there are indeed Id and Name fields in the list (IEnumerable) you provided.
    The problem with your code is that there are no elements named Id and Name when you send an empty array of anonymous objects, therefore the compiler cannot conclude that this is valid code.

    If you want to be able to send an empty array, you will have to refrain from using anonymous types.

    Try this:

        public struct myListType
        {
            public int Id;
            public string Name;
        }
    

    Now you can create your MultiSelectList as follows:

    Items = new MultiSelectList(
        new List<myListType>(),
        "Id",
        "Name"
    );
    

    I left out the selecteditemIDs because there is no use for it when the list is empty, it can only create issues.

    Although I am still not certain why you want to do this. I suspect there is a better way, if you can elaborate your intentions.

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

Sidebar

Related Questions

Does anyone know why UsernameExists wont return True. I must have my syntax messed
Im using PHP Active Record - Does anyone know how you kill a connection
Does anyone know why a library initialized within dlopen() would initialize a static variable
Does anyone know if there is a way to generate different code in the
Does anyone know of a free tool, similar to what is built into Visual
Does anyone know of a mechanism in Sybase ASA 9 / Sybase SQL Anywhere
Does anyone know of any websites, or (preferably) downloadable packages that you can use
Does anyone know of a way to contain a nonbreaking space in an html
Does anyone know how to make entity_id visible on the frontend as a sortable
Does anyone know of a good way to assert if a NameValueCollection is equivalent?

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.