0
我有一個完美的切換按鈕。在JavaScript和觀點是如下:ajax發佈到控制器之前Jquery對話框配置+ asp .net mvc3 + c#
的jQuery:
$('.list-delist-link').delegate("a", "click", function (e) {
var obj = $(this);
if ($(this).hasClass('delist-property')) {
// Post to controller
e.preventDefault();
} else {
// Post to controller
e.preventDefault();
}
});
查看:
<div class="list-delist-link">
@if(item.IsPropertyDisabled) {
@Html.ActionLink("List", "Enable", "Property", new { id = item.PropertyId }, new { @class="list-property other-button" })
} else {
@Html.ActionLink("Delist", "Disable", "Property", new { id = item.PropertyId }, new { @class="delist-property other-button" })
}
</div>
不過,現在我想的AJAX動作之前加一個確認對話框。但是,當我嘗試這樣做時,一切都會崩潰......我不知道爲什麼。我有佈局頁的jQuery和CSS文件
我所做的更改如下:
更改jQuery的:
var obj;
$('.list-delist-link').delegate("a", "click", function (e) {
obj = $(this);
$("#dialog-confirm").dialog(open):
e.preventDefault();
});
附加jQuery的模態確認:
$(function() {
$("#dialog-confirm").dialog({
resizable: false, height:140, modal: true,
buttons: {
"Delete all items": function() {
if (obj.hasClass('delist-property')) {
// Post to controller
} else {
// Post to controller
}
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
}
});
});
附加格:
<div id="dialog-confirm" title="Are you sure?">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
你能告訴我什麼是錯的嗎?
我會嘗試,但我不認爲這是問題,因爲該鏈接甚至沒有去jQuery的...它直接進入頁面,並獲得404錯誤,因爲它只能通過POST操作訪問。我甚至試圖在委託單擊中發出警報,但點擊不會在jQuery中...任何想法? – Tripping
'$(「#dialog-confirm」)。dialog(open)'使用'對話框(「打開」)' –
並使用'@ Ajax.ActionLink'而不是'@ Html.ActionLink' –