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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:13:43+00:00 2026-06-14T05:13:43+00:00

I’m new with MVC3 framework. So I was practicing and trying to learn how

  • 0

I’m new with MVC3 framework. So I was practicing and trying to learn how to have a Cascading dropdownlist using jquery. And I found this sample by Rick Anderson: http://blogs.msdn.com/b/rickandy/archive/2012/01/09/cascasding-dropdownlist-in-asp-net-mvc.aspx

So I tried to customize my own website with this sample in order to have a cascading dropdownlist. Here is my controller:

private SelectList GetMakeSelectList()
    {
        var makeQry = from m in db.Car
                      orderby m.Make
                      select m.Make;
        return new SelectList(makeQry.ToArray(), "Make");
    }

    public ActionResult MakeList()
    {
        if (HttpContext.Request.IsAjaxRequest())
            return Json(GetMakeSelectList(), JsonRequestBehavior.AllowGet);

        return RedirectToAction("Categories");
    }

    public ActionResult ModelList(string Make)
    {
        string make = Make;
        var model = from s in db.Car
                     where s.Make == make
                     select s.Model;

        if (HttpContext.Request.IsAjaxRequest())
            return Json(new SelectList(
                            model.ToArray())
                       , JsonRequestBehavior.AllowGet);

        return RedirectToAction("Categories");
    }

    public ActionResult Categories()
    {
        return View();
    }

and here is my model:

public class Car
{
    public int ID { get; set; }

    public String Make { get; set; }

    public String Model { get; set; }

    public decimal Price { get; set; }

    public String Edition { get; set; }

    public String Type { get; set; }

    public decimal Consumption { get; set; }

    public decimal Acceleration { get; set; }

    public decimal Horsepower { get; set; }

    public bool? Convertible { get; set; }
}
public class MovieDBContext : DbContext
{
    public DbSet<Car> Car { get; set; }
}

The problem is: String Make in ModelList method is null.
So I’m trying to not set my values manually in model class but set them just in the database.

My guess is: that the SelectList(makeQry.ToArray(), “Make”), the selected value’s type that I’m using is not what it expects to be. But I have no idea how to pass the expected type for a query.

And I’m using Jquery for this.
I would really appreciate any help.

Update:
Here is the View:

@model IEnumerable<Cars.Models.Car>

<script src="@Url.Content("~/Scripts/GetMake.js")"></script>
<script src="@Url.Content("~/Scripts/makeModel.js")"></script>
<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/CategoriesStyle.css")" />

@using (Html.BeginForm("Categories", "Category", FormMethod.Post, 
new { id = "CategoryFormID", 
    data_modelListAction = @Url.Action("ModelList"),
    data_makeListAction = @Url.Action("MakeList")})) {

<div id="content">
    <fieldset>
        <legend>Advanced Search</legend> 

        <div class="myform">

            <p>Search the car you're looking for in all details you can imagine right here!</p>

            <div id="MakeDivID">
                <label>Make</label>
                <select id="MakeID" name="Make"></select>
            </div>

            <div id="ModelDivID">
                <label>Model</label>
                <select id="ModelID" name="Model"></select>
            </div>



            <button type="submit" id="SubmitID">Search</button>
        </div>
    </fieldset>
</div>

}

and this would be my Jquery where I fill the dropboxes and call the methods:

this is GetMake.js

$(function () {
var URL = $('#CategoryFormID').data('makeListAction');
$.getJSON(URL, function (data) {
    var items = "<option>Select a Car Make</option>";
    $.each(data, function (i, make) {
        if (make.Text.indexOf("\'") > -1) {
            s = make.Text;
            alert(s + ": Country.Value cannot contain \'")
        }
        items += "<option>" + make.Text + "</option>";
    });
    $('#MakeID').html(items);
});
});

and this is makeModel.js:

$(function () {
$('#ModelDivID').hide();
$('#SubmitID').hide();
$('#MakeID').change(function () {
    var URL = $('#CategoryFormID').data('modelListAction');
    $.getJSON(URL + '/' + $('#MakeID').val(), function (data) {
        var items = '<option>Select a Model</option>';
        $.each(data, function (i, model) {
            items += "<option>" + model.Text + "</option>";
            // state.Value cannot contain ' character. We are OK because state.Value = cnt++;
        });
        $('#ModelID').html(items);
        $('#ModelDivID').show();
    });
});
$('#ModelID').change(function () {
    $('#SubmitID').show();
});
});

Second Update:
I forgot the mention the result that I get which is not what I’m looking for.
The result is that the first dropbox appears with all the correct values inside, when I click one of them, the second dropbox appears but it’s empty since I’m not passing the Make object is null in ModelList().

Third Update:
here is my routing as you asked. I hope this is what you were looking for.

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Cars
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode, 
// visit http://go.microsoft.com/?LinkId=9394801

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        // Use LocalDB for Entity Framework by default
        Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }
}
}
  • 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-14T05:13:45+00:00Added an answer on June 14, 2026 at 5:13 am

    Having seen your routes, I think this is your issue:

    public ActionResult ModelList(string Make)
    

    Your routes say that the parameter must be called id, so that it can be mapped (this is the default routing.. which is why I wanted to double check).

    routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // <---- This part here says {id}
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    

    To fix your issue, you probably only need to change the ModelList function to be this:

    public ActionResult ModelList(string id) {
        string make = id; // assign the string id to the make variable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to

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.