大家好,我在mvc和jquery
中使用webmethod绑定下拉列表时遇到错误无法加载资源:服务器响应状态为500(内部服务器错误)
我的代码就像这样
web服务
[WebMethod]
public static List<ListItem> BindDESG()
{
AdoConClass getado = new AdoConClass();
string query = "select Pk_DeptId,DepartmentName from emp_Master_Department where IsActive=1";
DataTable dt=getado.retrievedata(query);
List<ListItem> Desg = new List<ListItem>();
if (dt.Rows.Count>0)
{
Desg.Add(new ListItem
{
Value = dt.Rows[0]["Pk_DeptId"].ToString(),
Text = dt.Rows[0]["DepartmentName"].ToString()
});
}
return Desg;
}
Jquery的
$(document).ready(function () {
$.ajax({
type: "POST",
url: "../../Services/NewEMP/BindDesgDDL.asmx/BindDESG",
data: "{}",
contentType: 'application/json; charset=utf-8',
success: function (r) {
var ddlCustomers = $("[id*=sDesg]");
ddlCustomers.empty().append('<option selected="selected" value="0">Please select</option>');
$.each(r.d, function () {
ddlCustomers.append($("<option></option>").val(this['Value']).html(this['Text']));
});
},
error: function (msg) { alert(msg); }
});
Html标记
<select class="form-control" id="sDesg"></select>