从后台读取数据绑定到dropdownList,option选项value动态赋值,具体实现如下,感兴趣的朋友可以参考下哈
复制代码 代码如下:
$(document).ready(function () {
loadSchools();
});
function loadSchools() {
var url = "@Url.Action("GetSchools")";
$.ajax({
url: url,
type: "GET",
dataType: "json",
error: function () {
alert("Error");
},
success: function (data) {
var items = "";
$.each(data, function (i, school) {
items += "<option value=\"" + school.SchoolId + "\">" + school.SchoolName + "</option>";
});
$("#SchoolId").html(items);
}
});
}
您可能感兴趣的文章: