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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:57:31+00:00 2026-06-10T12:57:31+00:00

I have a webpage with 2 list box ( list1, list2 ), I can

  • 0

I have a webpage with 2 list box (list1, list2), I can shift items from one listbox to the other and back. When I click on the submit button, I want to return all the items value in list2 to the httppost method.

I have 3 problems:

  1. How to definite the property for the selected list?
  2. How to have a initial empty list (for list2)? list1 has populated items?
  3. How to return all of list2 items to model, when submit button is clicked ?

Model:

public class TestModel
{
    public List<SelectListItem> OptionList { get; set; }
    public List<SelectListItem> SelectedOptionList { get; set; }
    public string[] SelectedOptions { get; set; }
}

Controller:

private TestModel testModel  = new TestModel();

public ActionResult TestPage()
{
    ViewBag.Message = "Test Page";

    testModel.OptionList = new List<SelectListItem>();

    for (int i = 1; i <= 100; i++)
    {
        SelectListItem item = new SelectListItem();
        item.Text = "Option " + i.ToString();
        item.Value = item.Text;

        testModel.OptionList.Add(item);
    }

    return View("TestView", testModel);
}

[HttpPost]
public ActionResult TestPage(TestModel formModel)
{
    testModel.SelectedOptionList = formModel.SelectedOptionList;
    testModel.SelectedOptions = formModel.SelectedOptions;

    //do something
    return RedirectToAction("TestPage");
}

View:

@model EngineeringDataAnalysisGui.Models.TestModel

@{
    ViewBag.Title = @ViewBag.Message;
}

@section Subtitle
{
    @ViewBag.Message
}

<table width="100%">
@using (Html.BeginForm("TestPage", "RetrieveData", FormMethod.Post))
{
    <tr>
        <td>Event List:</td>
        <td>@Html.ListBox("lstEventSelection", Model.OptionList, new { id = "list1", Multiple = "multiple", Size = 15, style = "width: 100%;" })</td>
    </tr>
    <tr>
        <td></td>
        <td>
            <table style="text-align:center; width: 100%">
                <tr>
                    <td id="buttonCol">
                        <input type="button" id="btnAddAllEvent" title="Add All Events" onclick="moveAllOptions('list1','list2', true)" />
                        <input type="button" id="btnAddEvent" title="Add Selected Events" onclick="moveSelectedOptions('list1','list2', true)" />
                    </td>
                    <td id="buttonCol">
                        <input type="button" id="btnRemoveEvent" title="Remove Selected Events" onclick="moveSelectedOptions('list2','list1', true)" />
                        <input type="button" id="btnRemoveAllEvent" title="Remove All Events" onclick="moveAllOptions('list2','list1', true)" />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>Selected Event List:</td>
        @*Not sure how to add the listbox*@
        <td>@*Wrong*@@Html.ListBoxFor(x => x.SelectedOptions, Model.SelectedOptionList, new { id = "list2", Multiple = "multiple", Size = 15, style = "width: 100%;" })</td>
    </tr>
    <tr>
        <td><input type="submit" value="submit" /></td>
    </tr>
}
</table>
  • 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-10T12:57:32+00:00Added an answer on June 10, 2026 at 12:57 pm

    1) How to definite the property for the selected list?
    @Html.ListBoxFor(x => x.SelectedOptions, new MultiSelectList(Model.SelectedOptionList), new { id = "list2", Multiple = "multiple", Size = 15, style = "width: 100%;" })

    2) How to have a initial empty list (for list2)? list1 has populated items.
    In controller set an empty list testModel.SelectedOptionList = new List<SelectListItem>();

    3) How to return all of list2 items to model when submit button is clicked
    Probably you need to set all the items in list2 as selected (using jquery) before submitting. All the selected items in list2 items will bind to TestModel.SelectedOptions on submit.

    Please look around, there are a lot of answers already in SO related to Html.ListBoxFor. for e.g Challenges with selecting values in ListBoxFor

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

Sidebar

Related Questions

I have a webpage that shows a list of results. I click on one
I have a list of items on my web page that the user can
HELLO i have one dropdown box and one listbox , my dropdown box values
I have a ListBox in my webpage that is bound from database in this
I have a webpage that displays a very large list of data. Since this
I have a webpage built with a dropdown that has a list of books.
I have a webpage written in HTML. I have a dropdown list that is
I have a list of categories on my webpage. They are stored on mysql
I have a web page containing a filtering text box and a list box.
I have a webpage with a combo box on the page which is loaded

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.