Friday, April 15, 2011

Cascading Dropdown in ASP.NET MVC using jQuery

 

 

 

 

 

$(document).ready(function () {
 
    $.ajaxSetup({ "error": function (XMLHttpRequest, textStatus, errorThrown) {
        alert(textStatus);
        alert(errorThrown);
        alert(XMLHttpRequest.responseText);
    } 
    });
 
    $("#ddrCountry").change(function () {
        var url = "/Home/AsyncGetCountryLists";
        //alert(url);
        $.getJSON(url, { siteId: $("#ddrCountry option:selected").val() }, function (data) {
            $("#ddrState").empty();
            $("#ddrState").append("<option value=''> </option>");
            $.each(data, function (index, optionData) {
                $("#ddrState").append("<option value='"
                                           + optionData.Value
                                          + "'>" + optionData.Text
                                           + "</option>");
            });
            
        });
    });
});

No comments:

Post a Comment