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).
You are not sending the data of the form… You are only sending
__RequestVerificationToken:in your ajax request.Maybe try:
This way, you add to data the values in the form inputs and then add your token to it.