【问题标题】:Loading MVC Dropdowns using viewbags ajax when changing a dropdown?更改下拉列表时使用viewbags ajax加载MVC下拉列表?
【发布时间】:2018-05-07 12:27:55
【问题描述】:
@Html.DropDownList("CountryID", (SelectList)ViewBag.CounrtyList,new { style = "width:150px;" })

@Html.DropDownList("CityID", (SelectList)ViewBag.CityList,new { style = "width:150px;" })

@Html.DropDownList("StateID", (SelectList)ViewBag.StateList,new { style = "width:150px;" })

@Html.DropDownList("DistrictID", (SelectList)ViewBag.DistrictList,new { style = "width:150px;" })

更改 Country 下拉菜单时,如何在单个 ajax 调用中更改城市、州和地区值?

【问题讨论】:

标签: ajax asp.net-mvc dropdown viewbag


【解决方案1】:

这个想法被称为级联下拉,你可以在这里看到这个技术:Cascading update of two @Html.DropDownListFor in MVC4 with model binding

它使用部分视图链接到示例,但可以返回 JSON。我认为这是最好的选择,因为您可以返回以下 JSON 对象:

{ cities: [], states: [], districts: [] }

然后将城市连接到正确的 DDL。或者使用上面链接的部分视图方法,但调用它 3 次(这样效率较低)。

【讨论】:

    猜你喜欢
    • 2017-03-15
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多