简体   繁体   中英

Change data in dropdownlist with ajax,jquery mvc

I have a dropdownlisftFor that populate some data from the database that is filtered, and a checkbox. The idea is that, when i uncheck the checkbox, I want to change the data, that is populated in the dropdownbox, with the data of the database without the filter.

Which is the good approach to make this?

Ajax和jQuery将是简单而更好的方法。

Suggested method would be to load your dropdown list as a separate action with a bool parameter of filtered . you can call this in your view with @Html.Action("DropDownList", new {filtered = true})

Then when you uncheck the check box call a function that replaces the dropdown with the action with unfiltered data.

$("#myCheckBox").click(function() {
    if($("#myCheckBox").attr("checked") == "checked"){
        $("#divContainingDropDown").load("../path/to/dropdown/action?filtered=true")
    } else {
        $("#divContainingDropDown").load("../path/to/dropdown/action?filtered=false")
    }
}

This function will work for filtering and unfiltering the data in your list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM