Intercept file upload submit using jQuery dialog
<p>I have a .net mvc application that allows users to submit an attachment. For this, I am not using anything special such as plugins, etc, just using a standard form post.</p>

<p>However, I'd like to intercept the request with a confirmation dialog, and only post on OK.</p>

<p>In order to do so, I am using preventDefault, otherwise the the dialog box only appears for a second, and then the form posts.</p>

<p>Seems pretty straight forward. The problem I'm running into is that because it's a file upload, I need to continue submission and essentially undo the preventDefault.</p>

<p>So the problem I am running into is that I have to use preventDefault in order to stop the standard submission, but it also stops submission completely upon the user selecting OK to continue. Again, because of the file upload, I have to allow default behavior, because trying to do it any other way, i.e. $.post('@Url.Action("etc", "etc")', $('#form').serialize());, will then cause the controller to not receive the uploaded file.</p>

<p>Here is my code thus far:</p>

<pre><code>    $(document).ready(function () {
    $("form").submit(function (e) {

        var evt = e || event;
        if (evt.preventDefault)
            evt.preventDefault();
        else
            evt.returnValue = false;

        $('#divConfirm').dialog({
            height: 200,
            width: 450,
            title: 'Confirm',
            modal: true,
            autoOpen: false,
            buttons: {
                "Continue": function () {
                    $(this).dialog("close");
                    return true;
                    //$.post('@Url.Action("etc", "etc")', $('#form').serialize());
                },
                "Cancel": function () {
                    $(this).dialog("close");
                    //evt.preventDefault();
                }
            }
        });
        $('#divConfirm').dialog("open");
    });
});
</code></pre>

<p>So preventDefault stops all submision even on acceptance, but removing it prevents the dialog completely, only flashing the dialog box for a second. I have searched similar posts, but not found any solutions yet.</p>

<p>Any help is greatly appreciated.</p>
