ajax.beginform onsuccess updatetargetid 隐藏输入

发布于 2024-09-08 10:01:56 字数 1926 浏览 6 评论 0原文

我试图通过将函数附加到 ajax.beginform 上 ajaxoptions 的 onsuccess 属性来调用 jquery ui 对话框。

<script type="text/javascript">
    // Dialog
    $(document).ready(function () {
        $('#dialog').dialog({
            autoOpen: false,
            width: 600,
            modal: true,
            buttons: {
                "Ok": function () {
                    $(this).dialog("close");
                }
            }
        });
    });
</script> 

在一个单独的脚本文件中,我有这个。

function EmailResult() {
   $('#dialog').dialog('open');
}

然后我有一个尚未实际连接的联系表单,控制器仅响应两个字符串响应之一。

<% using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "ContactResult",  OnSuccess="EmailResult" }))
{ %>

如果我从 Ajax.BeginForm 中取出 OnSuccess="EmailResult" 或者只是从我的 EmailResult 中删除 $('#dialog').dialog('open');函数错误消失了,所以显然这是 OnSuccess 属性和 Jquery UI 对话框的问题。

我的第一个问题是我是否做错了什么导致此功能不起作用和/或如果这不起作用那么是否有更好的解决方案。

我正在尝试创建一个对话框,显示消息是否已发送。我不想使用警报对话框。

我想这个错误会有所帮助,在 IE 8 调试器中,它在 MicrosoftAjax.js 库中出现未定义的错误。

此代码的 finally 块导致了问题,在 IE 8 的本地选项卡下,它显示 b 未定义。

    this._onReadyStateChange = function () {
    if (a._xmlHttpRequest.readyState === 4) {
        try {
            if (typeof a._xmlHttpRequest.status === "undefined") return
        } catch (b) {
            return
        }
        a._clearTimer();
        a._responseAvailable = true;
        try {
            a._webRequest.completed(Sys.EventArgs.Empty)
        } finally {
            if (a._xmlHttpRequest != null) {
                a._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
                a._xmlHttpRequest = null
            }
        }
    }
};

它更新的是

<%= Html.Hidden("ContactResult") %>

结果是整个问题,我将隐藏输入更改为 div 并且它工作得很好。不知道为什么,但是...如果其他人遇到这个问题,你就去...

I am trying to call a jquery ui dialog by attaching the function to the onsuccess property of the ajaxoptions on a ajax.beginform..

<script type="text/javascript">
    // Dialog
    $(document).ready(function () {
        $('#dialog').dialog({
            autoOpen: false,
            width: 600,
            modal: true,
            buttons: {
                "Ok": function () {
                    $(this).dialog("close");
                }
            }
        });
    });
</script> 

In a seperate script file I have this..

function EmailResult() {
   $('#dialog').dialog('open');
}

Then I have a contact form that is not actually wired up yet, the controller just responds with one of two string responses.

<% using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "ContactResult",  OnSuccess="EmailResult" }))
{ %>

If I take out the OnSuccess="EmailResult" from the Ajax.BeginForm or simply remove $('#dialog').dialog('open'); from my EmailResult function the error goes away so obvisouly this is an issue with the OnSuccess property and a Jquery UI Dialog.

My first question is am I doing something wrong that is causing this not to work and/or if this won't work then is there a better solution.

I am trying to create a dialog that comes up and says whether the message was sent. I do not want to use the alert dialog box.

I guess the error would help, in the IE 8 debugger it comes up with an undefined error in the MicrosoftAjax.js library

The finally block of this code is causing the problem and under the locals tab in IE 8 it says b is undefined.

    this._onReadyStateChange = function () {
    if (a._xmlHttpRequest.readyState === 4) {
        try {
            if (typeof a._xmlHttpRequest.status === "undefined") return
        } catch (b) {
            return
        }
        a._clearTimer();
        a._responseAvailable = true;
        try {
            a._webRequest.completed(Sys.EventArgs.Empty)
        } finally {
            if (a._xmlHttpRequest != null) {
                a._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
                a._xmlHttpRequest = null
            }
        }
    }
};

What it was updating was

<%= Html.Hidden("ContactResult") %>

Which turns out was the whole problem, I changed the Hidden Input to a div and it works perfectly. Not sure why but... if anyone else runs into this there you go...

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

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

发布评论

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

评论(1

终陌 2024-09-15 10:01:56

所以我想这就是我的想法。我开始了一个带有两个输入的新 mvc 项目,并开始只使用一个警报框,因为事实证明它与 jquery.ui 对话框插件无关。我让它正常工作,并在使用 ajax.beginform 运行后出现警报框。

长话短说..您不能在 Ajax.BeginForm 中对 UpdateTargetID 使用隐藏输入吗?我想这是一个问题和答案,但是将 UpdateTargetID 更改为“div”的 ID 修复了它并且它可以正常工作。您甚至可以将 Div 可见性设置为隐藏并且它可以工作。

So I guess this is what I figured out.. I started a new mvc project with two inputs and started just using an alert box as it turns out it was not related to the jquery.ui dialog plugin. I got it to work correctly with the alert box coming up after it was run using the ajax.beginform.

So long story short.. You can't use a Hidden Input for the UpdateTargetID in the Ajax.BeginForm? I guess this is kind of a question and the answer but changing the UpdateTargetID to the ID of a "div" fixed it and it works appropriately. You can even set the Div visibility to hidden and it works.

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