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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:07:28+00:00 2026-06-15T05:07:28+00:00

Firstly I’m using MVC 2.0. I am having trouble getting a selection with a

  • 0

Firstly I’m using MVC 2.0. I am having trouble getting a selection with a Multiselect listbox on the postback to my controller. Here is my Code:

Model

public class TestModel
{
    public MultiSelectList AvailableTestTypes { get; set; }
    public List<TestType> SelectedTestTypes { get; set; } 
}

public class TestType
{
   public long Id { get; set; }
   public string Name { get; set; }
   public bool isActive { get; set; }
}

Controller

public ActionResult Index(TestModel model)
{
    if (model == null) model = new TestModel();

    List<TestType> testList = new List<TestType>()
    {
        new TestType() { Id = 1, Name = "TESTING", isActive = true },
        new TestType() { Id = 2, Name = "TESTING2", isActive = true },
        new TestType() { Id = 3, Name = "TESTING3", isActive = true }
    };

    model.AvailableTestTypes = testList; //TODO: Fetch From Repository 
    return View(model);
}


[HttpPost]
public ActionResult PostForm(TestModel model)
{
    List<long> act = model.SelectedTestTypes != null ? model.SelectedTestTypes.Select(x => x.Id).ToList() : new List<long>();

View

 <%= Model != null && Model.AvailableTestTypes != null ?
                                    Html.ListBoxFor(x => x.SelectedTestTypes,
                                                             new MultiSelectList(Model.AvailableTestTypes, "Id", "Name", Model.SelectedTestTypes), 
                                                             new { @id = "testListboxId", @class = "blah", @title = "title" }) : null%>

After the Post to the Controller my Selected List count is 0 no matter how many I choose…
What am I getting wrong here?

I tried a few different solutions such as
Challenges with selecting values in ListBoxFor
but nothing worked 🙁

  • 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-15T05:07:29+00:00Added an answer on June 15, 2026 at 5:07 am

    The difference between your script and the example in the other script, is the fact that you’re trying to bind to a List, instead of a int[].

    When you want to populate a Multiselect Listbox, you will have to set a DataValueField and a DataTextfield, otherwise no value is set.

    model.AvailableTestTypes = new MultiSelectList(testList, "Id", "Name);
    

    Then try using this class:

    public class TestModel
    {
        public MultiSelectList AvailableTestTypes { get; set; }
        public int[] SelectedTestTypes { get; set; } 
    }
    

    In your PostForm action, you can use the Ids to retrieve the TestTypes.

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

Sidebar

Related Questions

Firstly here is my PHP CODE if(!isset($_POST['selection'])){ $missing['selection'] = $required['selection']; } if(empty($missing)) { post2session();
Firstly, thanks for your help. Here's my situation: I'm trying to edit the code
Firstly, I'm receiving the status code 200. In the php script I'm just having
Firstly, is there a command for getting help and parameters for each sos command
Firstly, the bash script works fine when I call it outside of ant. Here
Firstly, I am new to programming. I am currently having a website with 2
Firstly, YES, this is a duplicate issue that's been asked 100 times on here,
Firstly, I know I should be using proper Threading techniques (Threadpool, BeginInvoke, etc.) to
Firstly, I'm in C# here so that's the flavor of RegEx I'm dealing with.
Firstly - Z is Up in this problem. Context: Top down 2D Game using

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.