我正在尝试填充一个下拉列表,我仍然对 J 查询感到非常困惑,因为我对它很陌生。
这是我的代码:
在控制器中:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult GetTeams(StatisticModel model)
{
StatisticModel newModel = new StatisticModel(model.leagueId);
var teams = newModel.getTeams;
return Json(teams);
}
鉴于:
<%: Html.DropDownListFor(model => model.teamIdHome, Model.getTeams, new { @class = "dropdownlistStyle" })%>
jQuery:
$(function() {
$(".dropdownlistStyle").change(function () {
$.getJSON("/Admin/GetTeams", { FooId: $(".dropdownlistStyle").val() },
function(fooList) {
$("#NameList").empty();
$.each(fooList, function(i, foo) {
$("#NameList").append(""+ foo.Name + "");
});
});
});
});
在单击“获取团队”按钮时,结果如下:
[{"Selected":false,"Text":"Arsenal","Value":"1"},{"Selected":false,"Text":"阿斯顿维拉","Value":"3"}, {"Selected":false,"Text":"Cardiff City","Value":"20"},{"Selected":false,"Text":"Chelsea","Value":"4"},{ "选中":false,"文本":"水晶宫","值":"22"},{"选中":false,"文本":"埃弗顿","值":"5"},{"已选":false,"Text":"富勒姆","Value":"6"},{"已选":false,"Text":"赫尔城","Value":"21"},{"已选“:假,”文本“:"Liverpool","Value":"7"},{"Selected":false,"Text":"Manchester City","Value":"8"},{"Selected":false,"Text":"曼联","Value":"9"},{"Selected":false,"Text":"纽卡斯尔联","Value":"10"},{"Selected":false,"Text":"诺里奇","Value":"11"},{"Selected":false,"Text":"Southampton","Value":"13"},{"Selected":false,"Text":"斯托克城","Value":"14"},{"Selected":false,"Text":"Sunderland","Value":"15"},{"Selected":false,"Text":"斯旺西市","Value":"16"},{"Selected":false,"Text":"托特纳姆热刺队","Value":"17"},{"Selected":false,"Text":" West Bromwich Albion","Value":"18"},{"Selected":false,"Text":"West Ham United","Value":"19"}]
我确信我的 jquery 是不正确的,因为我是从论坛的样本中得到的。
请问有什么帮助吗?