I am not sure my approach is correct so I am open to any suggestions.
I am using MVC 3. I am using the standard Membership provider and have modified the standard MVC Account model. I have a view that Registers the user details as well as requires them to add Apartment details. Apartment details are added using a jquery dialog
and saving/appending the results back to a table in the view. One user can register many apartments. Because I need to parse the table data in the view ( as well as the user details), I am using jQuery to parse the table data into JSON and then using a AJAX
Post to send the data back to the controller. This part is working correctly, the data is saved to the database. However, after a successfull Registration, I would like to redirect to a View that informs the user to check their email account for the account
confirmation. I know this redirect doesnt work in the Controller ( not sure why) but I cant get the redirect to work in the Ajax Post either: In fact , I cant even get teh success alert to fire. Can anyone tell me where I am going wrong?
$('#register').click(function(event) {
var apartmentRowValues =
$('#complexes-table tbody tr').map(function() {
// $(this) is used more than once; cache it for performance.
var $row = $(this);
// For each row that's "mapped", return an object that
// describes the first and second <td> in the row.
return {
ComplexName: $row.find(':nth-child(1)').text(),
ApartmentNo: $row.find(':nth-child(2)').text()
};
}).get();
var json = {
UserName: $('#UserName').val(),
Email: $('#Email').val(),
Password: $('#Password').val(),
ConfirmPassword: $('#ConfirmPassword').val(),
FirstName: $('#UserName').val(),
LastName: $('#LastName').val(),
Apartments: apartmentRowValues
};
$.ajax({
url: '/Account/Register/',
type: 'POST',
dataType: 'JSON',
data: JSON.stringify(json),
contentType: 'application/json; charset=utf-8',
success: function() { alert("Ajax Post succeeded"); },
error: function() { alert("An error has occurred in the ajax post of the registration data: " + err.Message); }
});
});
(Please select 'Mark as Answer' if my response has helped you.)
calibur
Member
300 Points
124 Posts
I cant get a redirect to work
Mar 05, 2012 02:32 PM|LINK
I am not sure my approach is correct so I am open to any suggestions.
I am using MVC 3. I am using the standard Membership provider and have modified the standard MVC Account model. I have a view that Registers the user details as well as requires them to add Apartment details. Apartment details are added using a jquery dialog and saving/appending the results back to a table in the view. One user can register many apartments. Because I need to parse the table data in the view ( as well as the user details), I am using jQuery to parse the table data into JSON and then using a AJAX Post to send the data back to the controller. This part is working correctly, the data is saved to the database. However, after a successfull Registration, I would like to redirect to a View that informs the user to check their email account for the account confirmation. I know this redirect doesnt work in the Controller ( not sure why) but I cant get the redirect to work in the Ajax Post either: In fact , I cant even get teh success alert to fire. Can anyone tell me where I am going wrong?
$('#register').click(function(event) { var apartmentRowValues = $('#complexes-table tbody tr').map(function() { // $(this) is used more than once; cache it for performance. var $row = $(this); // For each row that's "mapped", return an object that // describes the first and second <td> in the row. return { ComplexName: $row.find(':nth-child(1)').text(), ApartmentNo: $row.find(':nth-child(2)').text() }; }).get(); var json = { UserName: $('#UserName').val(), Email: $('#Email').val(), Password: $('#Password').val(), ConfirmPassword: $('#ConfirmPassword').val(), FirstName: $('#UserName').val(), LastName: $('#LastName').val(), Apartments: apartmentRowValues }; $.ajax({ url: '/Account/Register/', type: 'POST', dataType: 'JSON', data: JSON.stringify(json), contentType: 'application/json; charset=utf-8', success: function() { alert("Ajax Post succeeded"); }, error: function() { alert("An error has occurred in the ajax post of the registration data: " + err.Message); } }); });