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