mvc jquery passing form values after user presses "Accept" button

Posted by gdubs on Stack Overflow See other posts from Stack Overflow or by gdubs
Published on 2012-09-06T15:30:58Z Indexed on 2012/09/06 15:38 UTC
Read the original article Hit count: 221

Filed under:
|
|

So I have a form and a submit button that posts the form to an action. But I wanted to show a popup where the user can deny or accept an agreement.

Here's my jquery

$(document).ready((function () {
            var dialog = $('#confirmation-dialog').dialog({
                autoOpen: false, width: 500, height: 600, resizable: false, modal: true,
                buttons: {
                    "Accept": function () {
                        $(this).dialog('close');
                        $.ajax({
                            type: 'POST',
                            data: {__RequestVerificationToken: $("input[name=__RequestVerificationToken]").val()}
                        });
                    },
                    "Cancel": function () {
                        $(this).dialog('close');
                    }
                }
            });
            $('#registration-submit').click(function (e) {
                var action = $(this.form);
                console.log(action);
                var form = $('form');
                dialog.dialog("open");
                return false;
            });
        }));

My problem with this is that it would post, but it would only send my AntiforgeryToken, and not the values of the form. But when it goes through the TryupdateModel it would go through for some reason but will not Save (cuz of the missing data that wasn't passed on the formcollection).

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about asp.net-mvc