views:

7

answers:

0

Is there any alternative to json data to cascade dropdowns? I am using country and state dropdown but cascading the data with json take too much time

 [HttpGet]
 public ActionResult States(int countryId)
 {
     DateTangoEntities _db = new DateTangoEntities();
     var tset = _db.States.Where(r => r.CountryID == countryId).Select(r =>
         new { r.StateName, r.StateID });
     return Json(tset, JsonRequestBehavior.AllowGet);
 }

and here is the jquery part

$(document).ready(function () {
    var countries = $("#Country");
    var regions = $("#States");

    countries.change(function () {
        regions.find('option').remove();
        $.getJSON('/Profile/States', { countryId: countries.val() }, function (data) {
            $(data).each(function () {
                $('#States').append('<option value="' + this.StateID + '">' + this.StateName + '</option>').resetSS();
            });
        });
    });
});