クリックするとダイアログを開くリンクがいくつかあります。
個々のコンテンツに応じて、ユーザー インターフェイスを更新する個々の関数を実行するためのロード関数、コールバック関数に別のタイトル、高さ、重み、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>