简体   繁体   中英

Form Submit on Click of button in jquery model popup

In my MVC3 (Razor) application i have a page which contains a form.

 @using (Html.BeginForm("SaveReceipt", "ClinicInvoiceReceipt", FormMethod.Post, new { id = "form1" }))
   { }

Like above. In the same page i have Jquery model popup and it contains a button. I want to submit the form form1 on the button click in the popup.

i tried

    $("#ReceiptSave").click(function (e) {
        e.preventDefault();
        $('#ConfirmationDiv').dialog('close');// for closing popup
        $("#form1").submit();
    });

But it does not works. If anybody know the reason please help me. am stuck on this.

In error console it shows the following error 在此输入图像描述

@using (Html.BeginForm("SaveReceipt", "ClinicInvoiceReceipt", FormMethod.Post, new { id = "form1" }))
{ 
    <input type="image" id="ReceiptSave" src="..." />
}
@using (Html.BeginForm("SaveReceipt", "ClinicInvoiceReceipt", FormMethod.Post, new { id = "form1" }))
{ 
    <p>main page form </p>
    <input type="button" id="ShowConfirmDiv" value="Submit" />
}

<div id="ConfirmationDiv">
    <p>Are you sure you want to submit this form?</p>
    <input type="button" id="ReceiptSave" value="Ok"/>
</div>

<script type="text/javascript">
    $(document).ready(function () {

        $("#ConfirmationDiv").dialog({
            autoOpen: false,
        });

        $("#ShowConfirmDiv").click(function () {
            $("#ConfirmationDiv").dialog("open");
        });

        $("#ReceiptSave").click(function (e) {
            e.preventDefault();
            $('#ConfirmationDiv').dialog('close'); // for closing popup
            $("#form1").submit();
        });
    });
</script>

在此输入图像描述

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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