我不是前端人员,但是我必须做些事情。 我有两个列表:
在我的HTML源代码中,我看到所有项目都放置为option
,但是当我单击DropDownList时,我看到0个项目可供选择。如果我删除选择器,则所有项目均可见。任何帮助表示赞赏。
@Html.DropDownList("showTeams", null, "-Select Team-", htmlAttributes: new { id = "ddshowTeams", @class = "selectCountry selectpicker show-tick form-control" })
@Html.DropDownList("showMembers", null, "-Select Team-", htmlAttributes: new { id = "ddshowMembers", @class = " selectCountry selectpicker show-tick form-control" })
Ajax调用:
debugger;
$(document).ready(function () {
//Dropdownlist Selectedchange event
$("#ddshowTeams").change(function () {
alert("pehla andar");
$("#ddshowMembers").empty();
$.ajax({
type: 'POST',
url: '@Url.Action("GetListLabels","CTComparer")',
dataType: 'json',
data: { id: $("#ddshowTeams").val() },
success: function (mems) {
console.log("wich ayaeee");
// states contains the JSON formatted list
// of states passed from the controller
$.each(mems, function (i, member) {
//alert('<option value="'
// + member.Value + '">'
// + member.Text + '</option>');
$("#ddshowMembers").append('<option value="'
+ member.Value + '">'
+ member.Text + '</option>');
});
},
error: function (ex) {
alert('Failed to retrieve states.' + ex);
}
});
return false;
})
});
Json方法:
[HttpPost]
public ActionResult GetListLabels(int id)
{
var list = GetLabelList(id)
.Select(p =>
new SelectListItem
{
Value = "",
Text = p.Name
});
// this.ViewBag.SourceLabels = this.GetListLabelsSelectedItems(id);
// this.ViewData["showMembers"] = this.GetListLabelsSelectedItems(0);
return Json(list, JsonRequestBehavior.AllowGet);
}