使用来自 MVC 页面的 jqModal ajax 调用的结果更新 div

发布于 2024-10-25 17:44:18 字数 1778 浏览 5 评论 0原文

这是我的场景。

我使用 jqModal 的 ajax 功能来调用 jqModal,该功能在模式对话框中显示表单。用户填写一些信息并提交表单,该表单返回一些 html 作为响应。

生成的 html 显示在 jqModal div 内。然后,用户单击“关闭”以关闭模式对话框。

到目前为止,这一切都工作正常。

相反,我想要做的是关闭提交时的对话框,并使用服务器的响应更新 div。

调用代码:

<script type="text/javascript">

    $(document).ready(function () {

        $('#jqmWindowContainer').jqm({
            modal: true,
            ajax: '.... url to display my form ...',
            onHide: myAddClose,
            ajaxText: 'Loading',
            toTop: true,
        });

        function myAddClose(hash) {
            hash.w.fadeOut('300', function () { hash.o.remove(); });
        }

    }); 

</script> 

调用页面的标记。单击“保存此搜索”会触发该对话框。

    <a href="#" class="jqModal">Save this search</a>  
    <span id="jqmWindowContainer" class="jqmWindow"></span> 

显示的表单:

   <div class="jqmPopupForm" id="jqmPopupForm">  
        <div id="loadingMessage" style="display: none;">
            Saving...
        </div>

        <% using (Ajax.BeginForm("Save", "AssetSearch", 
             new AjaxOptions() 
                 { HttpMethod = "Post", InsertionMode = InsertionMode.Replace,
                   UpdateTargetId = "jqmPopupForm", 
                   LoadingElementId = "loadingMessage"
                 }))
            {%>

            .... some html input elements go here ...

                <input type="submit" value="Save Search" />

                <a class="jqmClose" href="#">Cancel</a>                      

        <%
            }%>
    </div>

现在,整个 jqmPopupForm div 正在被表单提交的结果替换。

如何关闭对话框并更新页面上的 div,而不是让用户关闭对话框?

Here's my scenario.

I call jqModal using its ajax functionality that displays a form in the modal dialog. The user fills out some information and submits the form which returns some html in response.

The resulting html is being displayed inside the jqModal div. The user then clicks Close to dismiss the modal dialog.

This all works correctly so far.

Instead, what I want to do is close the dialog on submit and update a div with the response from the server.

Calling code:

<script type="text/javascript">

    $(document).ready(function () {

        $('#jqmWindowContainer').jqm({
            modal: true,
            ajax: '.... url to display my form ...',
            onHide: myAddClose,
            ajaxText: 'Loading',
            toTop: true,
        });

        function myAddClose(hash) {
            hash.w.fadeOut('300', function () { hash.o.remove(); });
        }

    }); 

</script> 

Calling page's markup. Clicking "Save this search" triggers the dialog.

    <a href="#" class="jqModal">Save this search</a>  
    <span id="jqmWindowContainer" class="jqmWindow"></span> 

Form that is displayed:

   <div class="jqmPopupForm" id="jqmPopupForm">  
        <div id="loadingMessage" style="display: none;">
            Saving...
        </div>

        <% using (Ajax.BeginForm("Save", "AssetSearch", 
             new AjaxOptions() 
                 { HttpMethod = "Post", InsertionMode = InsertionMode.Replace,
                   UpdateTargetId = "jqmPopupForm", 
                   LoadingElementId = "loadingMessage"
                 }))
            {%>

            .... some html input elements go here ...

                <input type="submit" value="Save Search" />

                <a class="jqmClose" href="#">Cancel</a>                      

        <%
            }%>
    </div>

Right now, the entire jqmPopupForm div is being replaced by the results of the form submit.

How can I close the dialog and update a div on the page instead of making the user dismiss the dialog?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月隐月明月朦胧 2024-11-01 17:44:18

您可以通过向表单添加值为 $('#jqmWindowContainer').jqmHide();onSubmit 属性来关闭模式窗口。这应该允许在关闭模式时提交表单。

更新:

在 ASP 代码的 ajaxOptions 部分中,添加属性 onSuccess 并指定关闭模式窗口的函数。

    <% using (Ajax.BeginForm("Save", "AssetSearch", 
         new AjaxOptions() 
             { HttpMethod = "Post", InsertionMode = InsertionMode.Replace,
               UpdateTargetId = "jqmPopupForm", 
               LoadingElementId = "loadingMessage",
               OnComplete = "validateForm"
               OnSuccess = "closeWindow"
             }))
        {%>    

其中 closeWindow 是将关闭模式窗口的 JavaScript 函数的名称,并且
validateForm 是 JavaScript 函数的名称,它将在提交之前验证表单。

参考资料:
http://msdn.microsoft.com/en-us/library/dd460243.aspx
http://msdn.microsoft.com/en -us/library/system.web.mvc.ajax.ajaxoptions.aspx

You can close the modal window by adding an onSubmit attribute to the form with the value $('#jqmWindowContainer').jqmHide();. That should allow for the submission of the form while closing the modal.

UPDATE:

In the ajaxOptions portion of your ASP code, add the property onSuccess and specify a function that closes the modal window.

    <% using (Ajax.BeginForm("Save", "AssetSearch", 
         new AjaxOptions() 
             { HttpMethod = "Post", InsertionMode = InsertionMode.Replace,
               UpdateTargetId = "jqmPopupForm", 
               LoadingElementId = "loadingMessage",
               OnComplete = "validateForm"
               OnSuccess = "closeWindow"
             }))
        {%>    

where closeWindow is the name of the JavaScript function which will close the modal window, and
validateForm is the name of the JavaScript function which will validate the form before submission.

References:
http://msdn.microsoft.com/en-us/library/dd460243.aspx
http://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxoptions.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文