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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:51:29+00:00 2026-06-11T22:51:29+00:00

I have been searching a lot on Google and Stackoverflow for soltuions on how

  • 0

I have been searching a lot on Google and Stackoverflow for soltuions on how to Populate a Multiselect box with values that can be selected. But no luck.

public class PriceObj
{
    public int ID { get; set; }
    public decimal Price { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public virtual ICollection<PriceGroupObj> PriceGroup {get; set;}
}

public class PriceGroupObj
{
   public int ID { get; set; }
   public string Name { get; set; }
}


public class PriceDatabaseContext : DbContext
{
    public DbSet<PriceObj> PriceObjs { get; set; }
    public DbSet<PriceGroupObj> PriceGroupObjs { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();

        modelBuilder.Entity<PriceObj>()
            .HasMany(g => g.PriceGroup)
            .WithMany()
            .Map(t => t.MapLeftKey("GroupID").MapRightKey("PriceID").ToTable("PriceGroup"));
    }


}

Then I want in to be able to choose all appropriated price groups for a price in the edit view of the price objects. But I do not get it working, it is not populating all the already created groups in the MultiSelect box.

This is the code I am using in the Razor veiw:

@Html.ListBoxFor(model => model.PriceGroup, Model.PriceGroup.Select(pg => new SelectListItem { Text = pg.Name, Value = pg.ID.ToString() }), new { Multiple = "multiple" })

The select element shows up on the website, but no values are to select from.

Please help me sort out, where my chain is falling of.

  • 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-11T22:51:30+00:00Added an answer on June 11, 2026 at 10:51 pm

    Use a view model that is adapted to the requirements of your view:

    public class PriceViewModel
    {
        public int[] SelectedPriceIds { get; set; }
        public IEnumerable<SelectListItem> Prices { get; set; }
    }
    

    A ListBoxFor requires 2 properties on your view model:

    1. A collection property of a primitive type (string[], id[], Guid[], …) that will hold the ids of the selected elements
    2. An IEnumerable<SelectListItem> property that will hold the list of all items

    and then in the view:

    @Html.ListBoxFor(x => x.SelectedPriceIds, Model.Prices)
    

    Now your controller actions will pass this view model to the view instead of your domain objects which simply are not adapted to what you are trying to achieve. It is inside the controller actions that you will populate this view model from your domain models.

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

Sidebar

Related Questions

I have been searching for a while, but can't seem to get a succinct
Here is my question. I have been searching a lot but i dont find
I have been searching through a lot of questions but they don't ask or
Have been searching how to convert a dictionary to a string. But the results
I have been searching for a command that will return files from the current
I have been searching in stackoverflow for a question similar to mine because it
I have been searching for quite a bit now but I have never been
I have been searching on this but it is surprisingly hard to come by
I have been searching all over the internet tonight, saw a lot of solutions
I've been searching a lot but I haven't found anything about this question. I'm

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.