Asp.Net MVC Ajax.BeginForm不通过Ajax提交 [英] Asp.Net MVC Ajax.BeginForm is not submitting via Ajax

查看:235
本文介绍了Asp.Net MVC Ajax.BeginForm不通过Ajax提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的形式如下:

<div id="contact-form" class="hidden" title="Online Request Form">
    @Using (Ajax.BeginForm("Contact", "Main",
                          Nothing,
                          New AjaxOptions With {.UpdateTargetId = "status", .HttpMethod = "post"},
                          New With {.id = "contactUs"}))
        @<div>
            @Html.LabelFor(Function(m) m.Name)<br />
            @Html.TextBoxFor(Function(m) m.Name)<br />
            @Html.LabelFor(Function(m) m.Phone)<br />
            @Html.TextBoxFor(Function(m) m.Phone)<br />
            @Html.LabelFor(Function(m) m.Email)<br />
            @Html.TextBoxFor(Function(m) m.Email)<br />
            @Html.LabelFor(Function(m) m.Question)<br />
            @Html.TextAreaFor(Function(m) m.Question)<br />
            @Html.LabelFor(function(m) m.Security)<br />
            @Html.TextBoxFor(Function(m) m.Security)<br />
            <noscript>
                <input type="submit" name="submit" value="Ok" />
            </noscript>
            @Html.ValidationSummary("Oops, please correct the errors.")<span id="status">@TempData("status")</span>
        </div>
    End Using
</div>

和我在一个jQuery的用户界面模态窗口打开它

And I'm opening it in a jQuery-UI Modal Window

<script>
    $(function () {

        // Open the modal dialog from the div.contact-us click event
        $('#contact-us').click(function () {
            $('#contact-form').dialog('open');
            return false;
        });

        // Manage the modal dialog behavior.
        $('#contact-form').dialog({
            modal: true,
            autoOpen: false,
            buttons: {
                Cancel: function () {
                    $(this).dialog('close');
                },
                Ok: function () {
                    $('form#contactUs').trigger('submit');
                }
            }
        });
    });

</script>

在我点击确定按钮,它被张贴到适当的控制器,但它不是通过AJAX发布

When I click the "OK" button, it is posting to the appropriate controller, however it is not posting via AJAX

    ''# fix the StackOverflow code coloring issue.
    <HttpPost()>
    Function Contact(ByVal contactForm As Models.ContactForm) As ActionResult
        ViewData("Testimonials") = Helpers.GetTestimonials

        If ModelState.IsValid Then
            ''# Submit the email
            TempData("status") = "Thank you, we will be in touch"
        Else
            ''# Return False
            TempData("status") = "Oops, please correct the errors."
        End If


        If Request.IsAjaxRequest Then
            Return Content(TempData("status").ToString)
        Else
            Return View("Index")
        End If
    End Function

我是什么做错了吗?我提交表单后,我的网址是 http://example.com/Main/Contact 它告诉我, IsAjaxRequest = FALSE

即使我不使用jQuery的-UI确定按钮,只需添加&LT;输入类型=提交名称=提交值=确定/&GT ; 来的形式,形式职位没有Ajax

Even when I don't use the jquery-ui "ok" button and simply add <input type="submit" name="submit" value="Ok" /> to the form, the form posts without Ajax

推荐答案

你有包括jQuery的AJAX脚本?我注意到这种行为时,我并没有包括它:

Do you have the jquery ajax script included? I've noticed this sort of behavior when I didn't include it:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

这篇关于Asp.Net MVC Ajax.BeginForm不通过Ajax提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆