0

在 asp.net web 应用程序中,我使用 AJAX 提交表单。我想在提交之前运行一个javascript代码。所以我这样做了:

@using (Ajax.BeginForm("SaveProductDetails", "Store", new AjaxOptions
{
HttpMethod = "Post",
LoadingElementId = "progress",
OnBegin = "BeforeSubmit()",
OnSuccess = "closeMe()",
OnFailure = "doAlert('An error occurred while trying to save your changes. Please contact your Administrator')"
}))

但问题是,在运行 BeforeSubmit() 函数后,提交停止了。表单未提交。

BeforeSubmit() 函数没有问题。如果我不使用 OnBegin 做任何事情,表单会正确提交。任何帮助是极大的赞赏。

4

1 回答 1

1

您可以执行以下操作。

查看代码

    @using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { @id = "frmId", @name = "frmId" }))
    {
            @*Your code*@
            @*You have to define input as a type button not as a sumit. *@            
            <input value="Submit" type="button" id="btnSubmit" onclick="ValidateUser()" />
    }

    <script type="text/javascript">

    function ValidateUser() {
    // Do your verification here.
    $("#frmId").submit();
    }

</script>
于 2012-06-08T11:40:03.920 回答