better way to load 2 dropdown in mvc

后端 未结 5 515
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 03:05

This is how i am loading on page load state and city dropdown:

My Controller method:

This is the first method which is calling when page is

5条回答
  •  心在旅途
    2020-11-22 03:42

    This is a correct approach, but you can simplify your javascript:

    function loadCities(obj) {
        $.getJSON("/Home/GetCities", function (data) {
            var html = '';
            $(data).each(function () {
                  html += ''
            });
            $("#ddlCity").html(html);
        });
    }
    

    Further possible simplification: Add the default item (Select City) server-side, so your javascript will be smaller.

提交回复
热议问题