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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:48:55+00:00 2026-06-05T14:48:55+00:00

I am trying to get a dropdown list to send back it’s selection on

  • 0

I am trying to get a dropdown list to send back it’s selection on HTTP POST along with the other related data. I can see the value inside a Form Collection, but I VS2010 tells me that the object is NULL when I look at the other posted entities.

This model has a many to one relationship:

[Key]
public int ProgramTypeId { get; set; }

public string ProgramType { get; set; }

public List<SurveyProgramModels> SurveyProgramModel { get; set; }

This model uses the ProgramTypeId as a foreign key

public class SurveyProgramModels
    {
        [Key]
        public Guid ProgramId { get; set; }

        public virtual SurveyProgramTypeModels SurveyProgramTypeModels { get; set; }

        public int ProgramYear { get; set; }

        public int ProgramStatus { get; set; }

    }

Controller GET/POST

  //
        // GET: /SurveyProgram/Create

        public ActionResult Create()
        {

            SelectList typelist = new SelectList(db.SurveyProgramTypeModels.ToList(), "ProgramTypeId", "ProgramType", db.SurveyProgramTypeModels);
            ViewData["SurveyProgramTypeModels"] = typelist;

            return View();
        } 

        //
        // POST: /SurveyProgram/Create

        [HttpPost]
        public ActionResult Create(SurveyProgramModels surveyprogram, FormCollection collection)
        {


            SelectList typelist = new SelectList(db.SurveyProgramTypeModels.ToList(), "ProgramTypeId", "ProgramType", db.SurveyProgramTypeModels);
            ViewData["SurveyProgramTypeModels"] = typelist;

          //  int SelectedCollection = Int32.Parse(collection["ProgramTypeId"]);

            if (ModelState.IsValid)
            {
              surveyprogram.ProgramId = Guid.NewGuid();

                db.SurveyPrograms.Add(surveyprogram);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(surveyprogram);
        }

Select list in the view:

<div class="editor-field">
            @Html.DropDownList("ProgramTypeTypeModels", (IEnumerable<SelectListItem>)ViewData["SurveyProgramTypeModels"])
            @Html.ValidationMessageFor(model => model.SurveyProgramTypeModels)
        </div>

The Select list is correct when rendered in the view, and I can see the selected value as a part of the form collection. I’m not sure why the selected value isn’t being saved along with the other data for SurveyProgramModels.

Edit: I should also mention the data submits correctly when I remove the relationship between the two classes.

  • 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-05T14:48:59+00:00Added an answer on June 5, 2026 at 2:48 pm

    The form element is named as “ProgramTypeTypeModels” which would cause it not to bind back correctly. You also should create a Model to return to the View.

    Then include the SelectList as a property in the Model for the View

    Now you do something like:

     @Html.DropDownListFor(model => model.SurveyProgramTypeModels)
    

    And for the [HttpPost] you can then take the strongly typed Model as an argument and the aspnet binding will do all the work, no reason to DTO out of the FormCollection

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

Sidebar

Related Questions

So I'm trying to get a common dropdown list of event types in MVC.
I'm trying to get a list from a dropdown,since it's not a selectlist i've
Relatively new to MVC and trying to get a cascading dropdown list working for
I am trying to get data for my collection_select list. Details There are 4
I’m trying to configure a data source for a dropdown list. The database table
I'm trying to get a list of usernames and bind them to a DropDownList
I am trying to get the selected option from a dropdown and populate another
I'm trying to make a drop down menu using javascript/jquery but can't get my
I am trying set up a simple dropdown list but I dont seem to
I'm trying to get a dropdown menu to open when I hover over the

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.