在我当前的代码中,record
不会作为我可以迭代的列表返回。相反,它通过System.Collections.Generic.List'1[ProjectName.BodyStyle]
函数$.each
。
我需要的是一个列表,我可以通过并ID
从中BodyStyle1
提取来填写下拉列表。这是我的代码:
服务器端控制器:
Function Index(ByVal KovID As String) As List(Of BodyStyle)
Dim db As New Database1Entities
Dim record As New List(Of BodyStyle)
record = (From b In db.BodyStyles Where b.KovID = KovID Select b).ToList
Return record
End Function
查询:
function ajaxSuccess(record) {
var drop2 = $('#Vehicle_BodyStyle_value');
drop2.get(0).options.length = 0;
drop2.get(0).options[0] = new Option("Please Select One", "-1");
$.each(record, function (index, item) {
alert(index);
alert(item);
drop2.get(0).options[drop2.get(0).options.length] = new Option(item.Display, item.Value);
});
}
function ajaxError() {
$('#Vehicle_BodyStyle_value').get(0).options.length = 0;
$('#Vehicle_BodyStyle_value').get(0).options[0] = new Option("Error!", "-1");
alert("Failed to load styles");
}
$('#Vehicle_KovId_value').change(function () {
var kovID = $(this).val();
var drop2 = $('#Vehicle_BodyStyle_value');
if (kovID != null && kovID != '') {
drop2.get(0).options.length = 0;
drop2.get(0).options[0] = new Option('Please Select One', '-1');
$.ajax({
type: "GET",
url: '/Ajax/Index',
async: false,
data: { KovID: kovID },
contentType: "application/object; charset=utf-8",
success: ajaxSuccess,
error: ajaxError
});
}
});
我需要做的是record
作为我可以通过并从中提取信息的东西返回。任何帮助深表感谢!