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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:43:47+00:00 2026-05-27T05:43:47+00:00

Finally got my cascading dropdownlist working only to find it’s not repopulating in edit

  • 0

Finally got my cascading dropdownlist working only to find it’s not repopulating in edit mode. The first dropdownlist populates, and I’ve set the jquery to run on either the dropdown change, or the document ready. I’ve set an alert in the jquery, but it doesn’t enter the function in the controller to pull down the corresponding list for the second dropdown. Anyone know where I might be going wrong?

Here is the code – basically what I’m doing is selecting an airline, and from there, choosing from a list of flights associated with that airline:
View:

<div class="editor-field">
    @Html.DropDownListFor(x => x.FlightTime.AirlineID, Model.Airlines, "Select Airline")
    @Html.ValidationMessageFor(model => model.AirlineID)
</div>
<div class="editor-label">
    @Html.LabelFor(model => model.FlightID, "Flight")
</div>
<div class="editor-field">
    @Html.DropDownListFor(x => x.FlightTime.FlightID, Model.Flights, "Select Flight")
    <a href="#" class="flight">Add new</a>
    @Html.ValidationMessageFor(model => model.FlightTime.FlightID)
</div>
etc...

jQuery in View

$(document).ready(function () {
    var id = $('select#FlightTime_AirlineID').val();
    populate(id);

    $("#FlightTime_AirlineID").change(function () {
        var id = $('select#FlightTime_AirlineID').val();
        populate(id);
    });

    function populate(id) {
        alert('hello');
        //The line below is where it stops
        $.get('../FlightTime/GetFlightList/' + id, function (response) {
            var flights = $.parseJSON(response);
            var ddlSelectedFlight = $("#FlightTime_FlightID");

            // clear all previous options
            $("#FlightTime_FlightID > option").remove();

            // populate the products     
            for (i = 0; i < flights.length; i++) {
                ddlSelectedFlight.append($("<option />").val(flights[i].Value).text(flights[i].Text));
            }
            if (flights.length == 0) {
                ddlSelectedFlight.append($("<option />").val('').text('No flights added'));
            }
        });
    }
});

Controller function it should go into:

public string GetFlightList(string id)
{
    var flightList = this.GetFlights(Convert.ToInt32(id));
    var myData = flightList.Select(a => new SelectListItem()
    {
        Text = a.FlightNumber,
        Value = a.FlightID.ToString()
    });
    string text = new JavaScriptSerializer().Serialize(myData);
    return text;
}

ViewModel

public class FlightTimeViewModel
{
        private List<SelectListItem> _airlines = new List<SelectListItem>();
        private List<SelectListItem> _flights = new List<SelectListItem>();

        [DisplayName("Airline")] //Selected Value
        [Required(ErrorMessage = "Please select an airline")]
        public string AirlineID { get; set; }

        [DisplayName("Flight")] //Selected Value
        [Required(ErrorMessage = "Please select a flight")]
        public string FlightID { get; set; }

        public List<SelectListItem> Flights
        {
            get { return _flights; }
        }
        public List<SelectListItem> Airlines
    {
            get
            {
                foreach (Airline a in TimeTable.Repository.AirlineRepository.GetAirlineList())
                {
                    _airlines.Add(new SelectListItem() { Text = a.AirlineName.ToString(), Value = a.AirlineID.ToString() });
                }
                return _airlines;
            }
    }
        public FlightTime FlightTime { get; set; }
}

The function works fine in Create mode, but stops in the line of jQuery just after the alert when in edit mode. Been struggling with Viewmodels/dropdownlists, but thought I had it figured out until this.

Thanks

  • 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-27T05:43:48+00:00Added an answer on May 27, 2026 at 5:43 am

    Could you please try :

    $("#FlightTime_AirlineID").change(function () {
            var id = $('select#FlightTime_AirlineID').val();
            populate(id);
        }).change();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After many hair-pulling frustrations I've finally got one version of the PerlMagick module working
I finally got the Ws-Security working with CXF-BC & CXF-SE combination. I'm now trying
I finally got my django install working, however I'm noticing that the typical look
Hi I've finally got Suckerfish working and styled but in IE7 it is hidden
I've finally got this PHP email script working (didn't work on localhost…), but my
OK. I finally got my zend form working, validating, filtering and sending the contents
I have been working on this Tab View and I finally got it working
I finally got back to fleshing out a GitCommit message mode that I want
I've finally got Intellisense working for JQuery by applying patch KB958502 to Visual Studio
I finally got the DelayedJobs plugin working for Rails 2, and it does indeed

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.