Cascading dropdown

。_饼干妹妹 提交于 2019-12-11 07:14:36

问题


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();
            });
        });
    });
});

来源:https://stackoverflow.com/questions/3634877/cascading-dropdown

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!