我在javascript中定义了一个名为Bind_ChainHotel的函数,用于更改下拉列表选择,我通过ajax将数据填充到另一个下拉列表中。我在 MVC5 中使用 HtmlHelper.DropDownList 。每当我选择任何选项时,我都会在控制台中收到此错误。
@Html.DropDownList("ddlShellLevel", new List<SelectListItem>
{
new SelectListItem{Text="Chain",Value= "1"},
new SelectListItem{Text="Hotel",Value= "2"}
}, "Select Level", new { onchange = "Bind_ChainHotel(this.value);", @class = "form-control" })
Javascript
(function Bind_ChainHotel(id) {
$.ajax({
url: '@Url.Action("Bind_ChainHotel", "Shell")',
type: "POST",
data: { "id": id },
success: function (data) {
$("#ddlChain_Hotel").empty();
$.each(data, function (i, chain_hotel) {
$("#ddlChain_Hotel").append('<option value="' + chain_hotel.Value + '">' +
chain_hotel.Text + '</option>');
});
if (id == 1) {
$('#lblChainHotel').text('Select Chain');
$("#ddlChain_Hotel").prepend('<option value="0">Select Chain</option>');
}
else {
$("#lblChainHotel").text("Select Hotel");
$("#ddlChain_Hotel").prepend('<option value="0">Select Hotel</option>');
}
}
});
})();
最佳答案
删除开头和结尾的括号
function Bind_ChainHotel(id) {
$.ajax({
.....
});
};
关于javascript - Uncaught ReferenceError : Bind_ChainHotel is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26436573/