C# jQuery模态对话框第一次打开有效,后续打开失败

C# jQuery模态对话框第一次打开有效,后续打开失败,c#,jquery,razor,dialog,modal-dialog,C#,Jquery,Razor,Dialog,Modal Dialog,我有一个使用Razor引擎用C#编写的MVC项目。我通过jQuery调用一个modal,它加载一个表单,通过AJAX向我的控制器发布字段,并返回加载到调用DIV中的更新内容 这真是太棒了。。。一旦尝试再次打开模式(编辑其他行),表单将加载到浏览器中,就像重定向一样,而不是在模式对话框中显示它 在我看来,我是通过链接调用我的模式(自定义HTML帮助程序,仅为可读性而添加换行符): 我可以在第一次打开modal时没有问题。 我可以取消模式,并根据需要多次重新打开它 如果在模式中提交表单,则表单处理

我有一个使用Razor引擎用C#编写的MVC项目。我通过jQuery调用一个modal,它加载一个表单,通过AJAX向我的控制器发布字段,并返回加载到调用DIV中的更新内容

这真是太棒了。。。一旦尝试再次打开模式(编辑其他行),表单将加载到浏览器中,就像重定向一样,而不是在模式对话框中显示它

在我看来,我是通过链接调用我的模式(自定义HTML帮助程序,仅为可读性而添加换行符):

我可以在第一次打开modal时没有问题。

我可以取消模式,并根据需要多次重新打开它

如果在模式中提交表单,则表单处理正确,数据库更新正确,并且内容正确地重新加载到目标DIV中。但是,如果我尝试打开后续模式(用于编辑其他电话号码),则表单不会加载到模式中。而是作为新HTML文档的主体加载。

我尝试过以多种不同的方式关闭模式:

.dialog('destroy')

我还尝试在“a[data modal].on('click')函数中初始化模式,而不是在文档就绪时初始化

所有工作变更都是第一次工作,然后在第一次提交后失败

非常感谢您的任何建议

更新:添加了processForm()函数代码

function processForm(thisModalContent, thisCallingDiv, thisModalContainer, thisMethod, thisForm, thisTitle) {

    // Capture the form fields
    var formPost = jQuery(thisForm);

    // Serialize the fields to an array
    // This step is necessary to handle phone number mask removal
    var values = formPost.serializeArray();

    // Some code here removes phone masking and 
    // puts the raw numbers back into the array

    // Convert the serialized array to a single string for POST
    var serializedPost = jQuery.param(values);

    // Send data to controller and handle response
    jQuery.ajax({
        url: thisMethod,
        type: 'POST',
        data: serializedPost,
        error: function (x, e) {
            if (x.status === 0) {
                alert('You are offline!!\n Please Check Your Network.');
            } else if (x.status === 404) {
                alert('Requested URL not found.');
            } else if (x.status === 500) {
                alert('Internal Server Error.\n DataSent: \n' + serializedPost + '\n Response Text: \n' + x.responseText);
            } else if (e === 'parsererror') {
                alert('Error.\nParsing JSON Request failed.\n' + x.responseJSON);
            } else if (e === 'timeout') {
                alert('Request Time out.');
            } else {
                alert('Unknown Error.\n' + x.responseText);
            }
        },
        success: function (result) {
            if (result.success) {
                //jQuery('div.modalContent').dialog('destroy').remove();  // Didn't Work
                //jQuery('div.modalContent').dialog('destroy');  // Didn't Work
                //jQuery('div.modalContent').remove();  // Didn't Work
                jQuery('div.modalContent').empty().dialog('close');
                jQuery(thisCallingDiv).load(result.url);
            } else {
                thisModalContent.html(result);
            }
        }
    });
return false;
}
另外,值得一提的是,虽然本例中的代码引用电话号码,但我在同一页面上有一个地址DIV。地址编辑链接click调用相同的jQuery模式

如果我提交电话编辑,则来自电话编辑链接的后续呼叫将中断

但是我可以成功地调用地址编辑模式…一次。然后对它的后续调用被中断


刷新页面将修复两种链接类型(电话和地址)的模式。两种类型都可以重复打开和取消,直到其中一种被提交。然后,一种被破坏,但另一种在提交之前仍然有效。

因此,只有在调用
processForm()后尝试打开模式时,才会出现问题
?我怀疑里面有什么东西破坏了它。添加了processForm()函数代码和一些其他相关发现。
jQuery('div.modalContent').empty().dialog('close');
.dialog('destroy')
.remove()
.dialog('destroy').remove()
function processForm(thisModalContent, thisCallingDiv, thisModalContainer, thisMethod, thisForm, thisTitle) {

    // Capture the form fields
    var formPost = jQuery(thisForm);

    // Serialize the fields to an array
    // This step is necessary to handle phone number mask removal
    var values = formPost.serializeArray();

    // Some code here removes phone masking and 
    // puts the raw numbers back into the array

    // Convert the serialized array to a single string for POST
    var serializedPost = jQuery.param(values);

    // Send data to controller and handle response
    jQuery.ajax({
        url: thisMethod,
        type: 'POST',
        data: serializedPost,
        error: function (x, e) {
            if (x.status === 0) {
                alert('You are offline!!\n Please Check Your Network.');
            } else if (x.status === 404) {
                alert('Requested URL not found.');
            } else if (x.status === 500) {
                alert('Internal Server Error.\n DataSent: \n' + serializedPost + '\n Response Text: \n' + x.responseText);
            } else if (e === 'parsererror') {
                alert('Error.\nParsing JSON Request failed.\n' + x.responseJSON);
            } else if (e === 'timeout') {
                alert('Request Time out.');
            } else {
                alert('Unknown Error.\n' + x.responseText);
            }
        },
        success: function (result) {
            if (result.success) {
                //jQuery('div.modalContent').dialog('destroy').remove();  // Didn't Work
                //jQuery('div.modalContent').dialog('destroy');  // Didn't Work
                //jQuery('div.modalContent').remove();  // Didn't Work
                jQuery('div.modalContent').empty().dialog('close');
                jQuery(thisCallingDiv).load(result.url);
            } else {
                thisModalContent.html(result);
            }
        }
    });
return false;
}