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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:57:37+00:00 2026-06-14T09:57:37+00:00

When I submit a form, my Courses List into my ViewModel is getting null

  • 0

When I submit a form, my Courses List into my ViewModel is getting null values.
This is my ViewModel:

public class CandidateViewModel
{
    public string Name { get; set; }
    public IList<CourseViewModel> Courses { get; set; }

    public CandidateViewModel()
    {
        Name = "Kiwanax";
        Courses = new List<CourseViewModel>();
        for (int count = 0; count < 5; ++count)
        {
            Courses.Add(new CourseViewModel( 
                string.Format("Course_{0}", count), 5));
        }
    } 
}

public class CourseViewModel
{
    public long ID { get; set; }
    public string Name { get; set; }
    public OptionViewModel SelectedOption { get; set; }
    public IList<OptionViewModel> Options { get; set; }

    public CourseViewModel(string name, int numberOfOptions) 
    {
        Name = name;
        Options = new List<OptionViewModel>();
        for (int count = 1; count <= numberOfOptions; ++count)
        {
            Options.Add(new OptionViewModel(count.ToString(), 
                string.Format("Option {0}", count)));
        }
        SelectedOption = Options[0];
    }
}

public class OptionViewModel
{
    public string Value { get; set; }
    public string Description { get; set; }
}

OK. When I create DropDownLists based on my IList, it works fine.

<ul id="cursos">
@for (int count = 0; count < Model.Courses.Count; ++count)
{
    <li>
        @Html.DropDownListFor(i => i.Courses[count].SelectedOption,
            new SelectList(Model.Courses[count].Options, "Value", "Description", Model.Courses[count].SelectedOption))
                @Html.HiddenFor(i => i.Courses[count].ID)
                @Model.Courses[count].Name
            </li>
        }
        </ul>

But, when I do post from my form, I’m getting null values from that IList.

  • 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-14T09:57:40+00:00Added an answer on June 14, 2026 at 9:57 am

    You cannot bind dropdowns to complex property values:

    i => i.Courses[count].SelectedOption
    

    It must be bound to the corresponding primitive type that will be sent to the server:

    i => i.Courses[count].SelectedOption.Value
    

    Remember that in HTML the <select> element only sends the selected value as a simple string type to the server.

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

Sidebar

Related Questions

I got this code in my submit form <form id=myform action='hello.php' method='GET'> <input type=button
I am using this tutorial to create a login form http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/ It authenticates against
$('form').submit(function(){ this.action=http://www.sitename.com/post; return false; }); having altered the action attribute of the form ,i
My unversity's website has a search form to access the list of courses. You
I have a form for import data like this: <%= form_tag({ controller: 'courses', action:
it should submit form, :driver => :webkit do visit '/things/new' page.should have_content('Login') fill_in 'user_login',
Possible Duplicate: jQuery AJAX submit form I have a form on a page A,
I am working on a CSS/HTML submit form that I am going to make
Is it possible to add the OR operator to php isset submit form code
How can I manipulate the jquery tab, for example when a submit form is

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.