我有几个链接,单击时会打开一个对话框。
我仍然需要将单独的参数传递给对话框,因为根据其单独的内容,我需要另一个标题、高度、重量、contentUrl 用于加载函数、回调函数来执行更新用户界面的单独函数。
我如何必须重写以下代码才能达到我的目标?
<script type="text/javascript">
$(document).ready(function () {
// Does not cache the ajax requests to the controller e.g. IE7/9 is doing that...
$.ajaxSetup({ cache: false });
// the div holds the html content
var $dialog = $('<div></div>')
.dialog({
autoOpen: false,
title: 'generic title',
height: generic height,
width: generic width,
modal: true,
resizable: false,
hide: "fade",
show: "fade",
close: function (event, ui) {
// Clears all input values of the form
$("form")[0].reset();
},
open: function (event, ui) {
$(this).load('@Url.Action("Delete")');
},
buttons: {
"Ok": function () {
var form = $('form', this);
$.ajax({
url: $(form).attr('action'),
type: 'POST',
data: form.serialize(),
cache: false,
success: function (result) {
if (result.success) {
$dialog.dialog("close");
// Update UI with individual function/callback passed as parameter
}
else {
// Reload the dialog with the form to show model/validation errors
$dialog.html(result);
}
}
});
},
"Close": function () {
$(this).dialog("close");
}
}
});
$('#DeleteTemplate').click(function (e) {
var contentUrl = $(this).attr('href');
$dialog.dialog('open');
return false;
});
$('#CreateTemplate').click(function (e) {
var contentUrl = $(this).attr('href');
$dialog.dialog('open');
return false;
});
});
function updateDataGrid() {
// Pass this function to the dialog as individual function to be executed after the ajax call and result.success
}
function updateTreeView() {
// Pass this function to the dialog as individual function to be executed after the ajax call and result.success
}
</script>