Easiest way to create a cascade dropdown in ASP.NET MVC 3 with C#

As always you start with a model: public class MyViewModel { public int? Year { get; set; } public int? Month { get; set; } public IEnumerable<SelectListItem> Years { get { return Enumerable.Range(2000, 12).Select(x => new SelectListItem { Value = x.ToString(), Text = x.ToString() }); } } } then a controller: public class HomeController : … Read more

How to populate a cascading Dropdown with JQuery

It should as simple as jQuery(function($) { var locations = { ‘Germany’: [‘Duesseldorf’, ‘Leinfelden-Echterdingen’, ‘Eschborn’], ‘Spain’: [‘Barcelona’], ‘Hungary’: [‘Pecs’], ‘USA’: [‘Downers Grove’], ‘Mexico’: [‘Puebla’], ‘South Africa’: [‘Midrand’], ‘China’: [‘Beijing’], ‘Russia’: [‘St. Petersburg’], } var $locations = $(‘#location’); $(‘#country’).change(function () { var country = $(this).val(), lcns = locations[country] || []; var html = $.map(lcns, function(lcn){ return … Read more