2
我一直在寻找这个,并尝试了很多找到的解决方案,但没有在我的情况下工作。 在我的MVC 4应用程序下拉更改事件我打电话给一个JS方法将选定的值传递到控制器工作正常,但在控制台我一直在每个变化事件中得到这个错误continuoulsy。未捕获类型:未定义不是函数JS错误
以下是我的下拉剃刀来源:
<div>
@Html.LabelFor(model => model.CustId)
@Html.DropDownListFor(model => model.CustId, new SelectList(Model.ddlCust, "Value", "Text"), "All Customer", new { id = "CustID", onchange = "ShowCust()", @class = "form-control" })
@Html.ValidationMessageFor(model => model.CustId)
</div>
而且我JS客户端功能看起来像:
<script>
function ShowCust() {
var custId = $("#CustID").val();
var Url = "@Url.Content("~/Customer/GetCustId")";
$.ajax({
url: Url,
type: 'POST',
dataType: 'json',
data: { CustID: custId },
success: function (data) {
return data;
}
});
}
</script>
在控制台它抛出的错误在每个下拉变化:
uncaught type error: undefined is not a function.
最后在源代码中显示为:
<script>(function() {with (this[2]) {with (this[1]) {with (this[0]) {return function(event) {ShowCust()
};}}}})</script>
而且它标志着与前函数ShowCust({
ShowCust)括号下划线的部分。
我无法弄清楚我在这里做错了什么。
有没有人看到我的HTML或JavaScript的任何问题?或者我写脚本的方式?提前致谢。
你确定你包含具有'ShowCust'函数的文件到HTML页面本身吗? – 2014-09-23 06:17:05
@JibiAbraham是的,它在同一个剃刀视图中。 – Saroj 2014-09-23 06:31:11
哪条线发生错误? – Dropout 2014-09-23 06:38:14