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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:56:22+00:00 2026-06-03T07:56:22+00:00

My view: <div class=editor-label> @Html.LabelFor(model => model.UserList) </div> <div class=editor-field> @Html.ListBoxFor(model => model.SelectedUsers, new

  • 0

My view:

    <div class="editor-label">
        @Html.LabelFor(model => model.UserList)
    </div>
    <div class="editor-field">
        @Html.ListBoxFor(model => model.SelectedUsers, new MultiSelectList(Model.UserList, "Key", "Value", Model.SelectedUsers))
        @Html.ValidationMessageFor(model => model.UserList)
    </div>

My viewmodel:

public class UserListViewModel
{
    public UserListViewModel() :
        this(new List<KeyValuePair<string, string>>())
    {

    } 

    public UserListViewModel(IList<KeyValuePair<string, string>> userList)
    {
        this.UserList = userList;
        SelectedUsers = new List<string>();
    }      

    public IList<KeyValuePair<string,string>> UserList { get; set; }
    public IList<string> SelectedUsers { get; set; }
}

As it is now I only get the selected values and when I reach the controller my UserList is emptied so I can’t compare with that again. Is there any way I can return both the value and the text from the MultiSelectList or at least remember the contents of my UserList until I reach the controller?

  • 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-03T07:56:23+00:00Added an answer on June 3, 2026 at 7:56 am

    The Html.ListBoxFor helper renders a <select> element with the multiple attribute. In HTML when you place this tag in a form and submit the form only the selected values are sent to the server. That’s how HTML works. If you want to send the text as well you will have to use javascript. For example you could subscribe to the change event of the select element and then keep a hidden field inside the form that will be update with the list of the selected texts. But honestly don’t do that. In your POST controller action simply fetch the texts from the same location you fetched them in your GET action to display the form initially.

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

Sidebar

Related Questions

I have the following code in a view: <div class=wrap_select> @Html.DropDownList(dateRange, new SelectList(Model.DateRange, Value,Text),
This is My View: @foreach(var action in Model.Category.Actions) { <div class=action style=margin-right: 30px;> <input
A simple HTML form: <form enctype=application/x-www-form-urlencoded method=post action=/view/album/id/4><ol> <li class=no-padding><div class=element> <input type=hidden name=media
In my rails view(index.html.erb), i have following structure <div> <%= render :partial => create
I have a html structure like : <div onmouseover=enable_dropdown(1); onmouseout=disable_dropdown(1);> My Groups <a href=#>(view
I have below html code in one of the opensource project. <form action=/wiki/bin/view/Main/Search> <div
I have this model: public class ExchangeRate { [Key] public int ExchangeRateID { get;
My model classes are: public class User { public User() { Polls = new
I have a view model public class DeviceModelEntryViewModel { public int ID { get;
When you view a long thread in gmail a div appears at the bottom

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.