Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改下拉列表时使用viewbags ajax加载MVC下拉列表?_Ajax_Asp.net Mvc_Dropdown_Viewbag - Fatal编程技术网

更改下拉列表时使用viewbags ajax加载MVC下拉列表?

更改下拉列表时使用viewbags ajax加载MVC下拉列表?,ajax,asp.net-mvc,dropdown,viewbag,Ajax,Asp.net Mvc,Dropdown,Viewbag,在更改国家/地区下拉列表时,如何在单个ajax调用中更改城市、州和地区值?这种方法被称为级联下拉列表,您可以在这里看到这种技术: 它使用部分视图链接到一个示例,但可以返回JSON。我认为这是最好的选择,因为您可以返回以下JSON对象: @Html.DropDownList("CountryID", (SelectList)ViewBag.CounrtyList,new { style = "width:150px;" }) @Html.DropDownList("CityID", (Selec

在更改国家/地区下拉列表时,如何在单个ajax调用中更改城市、州和地区值?

这种方法被称为级联下拉列表,您可以在这里看到这种技术:

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

@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;" })
然后将城市连接到正确的DDL。或者使用上面链接的部分视图方法,但称之为3次(效率较低)。

建议您在
{ cities: [], states: [], districts: [] }