0

My view:

var token = $('input[name=__RequestVerificationToken]').val();

$.ajax({
    url: '/Account/TryRegister',
    type: 'post',
    data: { '__RequestVerificationToken': token,
            firstName: $('#FirstName').val(),
            lastName: $('#LastName').val(),
            email: $('#Email').val(),
            password: $('#Password').val() },
    success: function (outData) {
        alert('Success!');
    },
    error: function () {
        alert('Error!');
    }
});

My controller:

[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult TryRegister(string firstName, string lastName, string email, string password)
{
    return Json(true); // TEMP!
}

If I remove firstName, lastName, email and password from both, it works, otherwise, it just doesn't get to the controller. What am I missing here (all fields really exist)?

1 Answer 1

2

Make life easier on yourself and use JQuery's .serialize()

var formdata;

formdata= $(myform).serialize();

then in your ajax call... data: formdata,

Sign up to request clarification or add additional context in comments.

1 Comment

There was another problem somewhere else. My bad. Thank you anyway ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.