简体   繁体   English

未捕获类型:未定义不是函数JS错误

[英]Uncaught Type: Undefined is not a function JS error

I have been looking for this and tried with lot of found solutions but that didn't work in my case. 我一直在寻找并尝试使用许多找到的解决方案,但在我的情况下不起作用。 In my MVC 4 application with dropdown change event I am calling a JS method to pass the selected value to the controller which works fine but in console I've been getting this error continuoulsy in every change event. 在我的带有下拉更改事件的MVC 4应用程序中,我正在调用JS方法,以将选定的值传递给控制器​​,该控制器可以正常工作,但是在控制台中,每次更改事件中我都会不断收到此错误。

Following is my razor source for dropdown: 以下是我的下拉列表的剃须刀来源:

    <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> 

And my JS client function looks like: 我的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>

In Console it throws the error on every dropdown change: 在控制台中,它会在每次下拉更改时引发错误:

uncaught type error: undefined is not a function.

And finally in source it shows as: 最后在源代码中显示为:

<script>(function() {with (this[2]) {with (this[1]) {with (this[0]) {return function(event) {ShowCust()
};}}}})</script>

Also it marks the part with underline in braces before function ShowCust ( { ShowCust). 另外,它还在函数ShowCust( { ShowCust)之前的括号中用下划线标记该部分。

I am not able to figure out what exactly I am doing mistake over here. 我无法弄清楚我在这里到底在做什么错。

Does anyone see any issues with my html or javascript? 有人看到我的html或javascript有任何问题吗? Or the way I written the script? 还是我编写脚本的方式? Thanks in advance. 提前致谢。

I think you have miss out the '@' for Id & onChange

new { @id = "CustID", @onchange = "ShowCust()", @class = "form-control" }) new {@id =“ CustID”,@onchange =“ ShowCust()”,@class =“ form-control”})

@id = "CustID" @onchange = "ShowCust()" @id =“ CustID” @onchange =“ ShowCust()”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM