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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:00:51+00:00 2026-06-06T19:00:51+00:00

how to load cascading dropdownlist each other asp.net mvc3? how can i do? i

  • 0

how to load cascading dropdownlist each other asp.net mvc3? how can i do? i have been utilizing from
http://geekswithblogs.net/ranganh/archive/2011/06/14/cascading-dropdownlist-in-asp.net-mvc-3-using-jquery.aspx

but i can not. what is mymistake? i added debug red point on LoadJobByCustomerId method. But not working.Pleqase dont say make googling i do it in 48 hours…
View:


<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/ChildSite.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="../../Scripts/jquery-1.4.4.js">


    $(document).ready(function () {
        $("#ddlCustomers").change(function () {
            var idColour = $(this).val();
            $.getJSON("/Job/LoadJobByCustomerId", { customerId: idColour },
function (modelData) {
    var select = $("#ddlJobs");
    select.empty();
    select.append($('<option/>', {
        value: 0,
        text: "Select a Colour"
    }));
    $.each(modelData, function (index, itemData) {

        select.append($('<option/>', {
            value: itemData.Value,
            text: itemData.Text
        }));
    });
});
        }); 


</script>
  <% 
   using (Html.BeginForm())
      { %>

       <table style="padding:25px; margin:10px 10px 10px 10px;" id="sample">
                <tr><td>Customer Name: </td><td>
               <%= Html.DropDownList("Customers", null, "** Please Select **", new { id="ddlCustomers"})%>
                </td></tr>
                 <tr><td>Job Name:</td><td>
              <%= Html.DropDownList("Jobs", null, "** Please Select **", new { id = "ddlJobs" })%>
                </td></tr>
                </table>
                <br />
                <div>

                </div>
         <%}%>

</asp:Content>

Controller:


 public class JobController : Controller
    {
     public ActionResult Index()
        {
            ViewData["Customers"] = new SelectList(CustomerOperation.GetCustomers().Items, "Id", "Name", null);
            ViewData["Jobs"] = new SelectList(JobOperation.GetCustomersAssemblyList().Items, "scheduleId", "name", null);
            return View();
        }


        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult LoadJobByCustomerId(int customerId)
        {
            var jobs = JobOperation.GetCustomersAssemblyList(customerId).Items;

            var jobItems = jobs.Select(c => new SelectListItem()
            {
                Text = c.name,
                Value = c.scheduleId.ToString()

            });

            return Json(jobItems, JsonRequestBehavior.AllowGet);
        } 

  • 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-06T19:00:55+00:00Added an answer on June 6, 2026 at 7:00 pm

    For starters, the <script> tag in which you are loading jquery is not properly closed:

    <script type="text/javascript" src="../../Scripts/jquery-1.4.4.js">
    

    It should be like this:

    <script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery-1.4.4.js") %>"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#ddlCustomers').change(function () {
                var idColour = $(this).val();
                var url = '<%= Url.Action("LoadJobByCustomerId", "Job") %>';
                $.getJSON(url, { customerId: idColour }, function (modelData) {
                    var select = $("#ddlJobs");
                    select.empty();
                    select.append($('<option/>', {
                        value: 0,
                        text: "Select a Colour"
                    }));
                    $.each(modelData, function (index, itemData) {
                        select.append($('<option/>', {
                            value: itemData.Value,
                            text: itemData.Text
                        }));
                    });
                });
            }); 
        });
    </script>
    
    <% using (Html.BeginForm()) { %>
        <table style="padding:25px; margin:10px 10px 10px 10px;" id="sample">
            <tr>
                <td>Customer Name: </td>
                <td>
                    <%= Html.DropDownList(
                        "Customers", 
                        null, 
                        "** Please Select **", 
                        new { id = "ddlCustomers" }
                    )%>
                </td>
            </tr>
            <tr>
                <td>Job Name:</td>
                <td>
                    <%= Html.DropDownList(
                        "Jobs", 
                        null, 
                        "** Please Select **", 
                        new { id = "ddlJobs" }
                    )%>
                </td>
            </tr>
        </table>
    <% } %>
    

    Also jQuery 1.4.4’s kinda old. Maybe you wanna switch to a more recent version.

    Another things that I have fixed in your code is the usage of Url helpers instead of hardcoding urls, missing closing }); for the document.ready handler, broken markup with inconsistent opening and closing <tr> and <td> tags, …

    I don’t know how are you guys writing/indenting your code, but I would really recommend you putting a little more attention.

    And next time when developing a javascript intensive web application and something doesn’t work, your immediate reflex should be to look in the FireBug console or Chrome developer toolbar (depending on the web browser you are using) instead of posting on Stack Overflow without any investigation. FireBug would have alerted you on at least 50% of the errors you committed in your code.

    Further improvement of this code is to get rid of ViewData by introducing view models and the usage of strongly typed helpers, as I have exemplified in this post: https://stackoverflow.com/a/4459084/29407

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

Sidebar

Related Questions

i am developing a website using asp.net 3.5.i have created a cascading dropdownlist for
I have two cascading dropdowns and one gridview control. on page load iam binding
html load coming from NSString. I have the following problem: I get html code
I load a C++ DLL using DLLImport in my C# ASP.Net web application. The
I am relatively new at using ASP.NET MVC, however I have got experience with
I load the markers and polylines from a ajax page , each request data
I load content via jQuery load() but for each time I load a given
I load a webpage from my assets in a webview. Now i need to
I'm trying to create some cascading drop downs. I have my States loading via
I load cities from the data context into two different lists and bind them

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.