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

  • Home
  • SEARCH
  • 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 7658519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:12:45+00:00 2026-05-31T13:12:45+00:00

Im trying to use IEnumerable so it holds multiple selections so a user can

  • 0

Im trying to use IEnumerable so it holds multiple selections so a user can choose more then one value in my listbox.

This is how my ViewModel looks like:

    public class CreateViewModel
{
    public IEnumerable<string> SelectedValues { get; set; } 
    public IEnumerable<CoreValue> CoreValues { get; set; }
}

This is my GET in my controller:

public ActionResult Create()
{          
    CreateViewModel model = new CreateViewModel();
    model.CoreValues = AdminRepository.GetAllCoreValues();
    return View(model);
}

This how my view looks like:

@Html.ListBoxFor(m => m.SelectedValues, new MultiSelectList(Model.CoreValues, "Id", "Name"))

How do I code my POST action so that SelectedValues will be used to contain the selected values on the post?

Before Ienumerable I had string declared to CoreValueName in my ViewModel and I did something like this in my POST action which worked perfectly but now I changed it to Ienumerable and I have am not sure how to code so my selectedvalues will be used to contain the selected values in my post.

Question question = new Question();
var CoreValueID = int.parse(model.CoreValueName);
var GetAllCoreValuesID = AdminRep.GetByCoreValueID(CoreValueID);             
question.CoreValue.Add(GetAllCoreValuesID);
AdminRepository.AddQuestion(question);
AdminRepository.save();

This version of my POST action works perfectly beacuse model.SubjectType is declared as string in my Viewmodel:

    [HttpPost]
        public ActionResult Create(AdminCreateViewModel model)
        {

                Question question = new Question();       
                var SubjectTypeID = int.Parse(model.SubjecTypeName);
                var GetAllSubjecTypesID = AdminRep.GetBySubjectTypeID(SubjectTypeID);
                question.SubjectType.Add(GetAllSubjecTypesID);
                AdminRep.AddQuestion(question);
                AdminRep.save();
        }

This version of my Post action is not working beacuse Model.Selectedvalues is declared as Ienumerable string in my ViewModel. I tried to int.parse my model.SelectedValues but that doesnt work with Ienumerable. And GetByCoreValueID method takes int as argument so I have no idea how do to this. Do I need foreach?

 [HttpPost]
 public ActionResult Create(AdminCreateViewModel model)
 {
    Question question = new Question(); 
    var CoreValueID = model.SelectedValues;
    var GetAllCoreValuesID = AdminRep.GetByCoreValueID(CoreValueID); //
    question.CoreValue.Add(GetAllCoreValuesID);
    AdminRep.AddQuestion(question);
    AdminRep.save();

Thanks in advance!

  • 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-05-31T13:12:45+00:00Added an answer on May 31, 2026 at 1:12 pm

    You could have your POST controller action take the view model as argument. Then the SelectedValues property will contain a list of values that the user selected:

    [HttpPost]
    public ActionResult Index(CreateViewModel model)
    {
        model.SelectedValues will cnotain the selected values from the user here
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Concat() on multiple ISets to make one larger ISet.
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I'm trying to use xVal to validate the registration of a new user. I've
I' trying to use a Linq query to find and set the selected value
I'm trying to make use of the extended HTML Helper DisplayFor in this View:
I am trying to use a dynamic linq query to retrieve an IEnumerable<T> from
I am trying to understand the below use of a lambda expression. This code
I'm trying to use MongoDB to cache some data for me, but I can't

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.