简体   繁体   English

如何在MVC Mobile中停止Ajax表单发布上的页面更改

[英]How to stop page change on Ajax Form Posting in MVC Mobile

I am creating an application on MVC Mobile and having a problem. 我在MVC Mobile上创建了一个应用程序,并且遇到了问题。 Here i have a Partial view load on a page run-time by ajax. 在这里,我通过ajax在页面运行时上加载了部分视图。 In which i have a simple form which will submit with ajax request like bellow: 在其中我有一个简单的表格,它将与像波纹管一样的ajax请求一起提交:

@model Test.Models.TestModel
@using (this.Ajax.BeginForm("Create", "Test", Model, new AjaxOptions { UpdateTargetId = "divResult", LoadingElementId = "loading", LoadingElementDuration = 2000, HttpMethod = "Post" }, new { id = "frmCreate" }))
{
    @Html.AntiForgeryToken()

    <div class="messageBox">@Html.Raw(TempData["Message"])</div>
    <div class="atmForm">
        <div class="control-group">
            @Html.LabelFor(x => x.Name)
            @Html.TextBoxFor(x => x.Name, new { @placeholder = "Name", @class = "inputStyle" }) @Html.ValidationMessageFor(x => x.Name)
        </div>
        <div class="control-group">
            @Html.LabelFor(x => x.Notes)
            @Html.TextAreaFor(x => x.Notes, new { @placeholder = "Notes", @class = "inputStyle" }) @Html.ValidationMessageFor(x => x.Notes)
        </div>
    </div>
    <div class="form-actions2 clearfix">
        <input type="submit" class="btn btn-block" value="Create" data-ajax="false" id="btnFormSubmit" />
    </div>
}
<script type="text/javascript">
    $.validator.unobtrusive.parse("#frmCreate");
</script>

The problem is when user submit the form the controller called twice. 问题是,当用户提交两次被控制器调用的表单时。 First time it return the partial view and then again it calls and then jQuery Mobile change the page. 第一次返回部分视图,然后再次调用,然后jQuery Mobile更改页面。 I am Using MVC4 with jQuery Mobile 1.1.0 我将MVC4与jQuery Mobile 1.1.0一起使用

(please note that create.cshtml (desktop ver) works fine but create.Mobile.cshtml (mobility ver) havng this problem) (请注意,create.cshtml(台式机版本)工作正常,但create.Mobile.cshtml(移动版)存在此问题)

不要提交表单,使用$("#myForm").serialize()作为ajax数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM