I have a registration form and on successful registration, it redirects to another view.
I use a submit button to insert datas to database, I want to clear the values in the current view and redirect the user to logon page in another view under same controller.
The submit type is not performing the action mentioned in jquery.Please help me
here is my code preview
Account/register
Account/logon
Accountcontroller.cs
[HttpPost]
public ActionResult Register(RegisterModel model, FormCollection form)
{
try {
---code
}
catch {
}
}
register.cshtml
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { id = "accForm" }))
{
@html.textboxfor(.....)
@html.textboxfor(.....)
@html.textboxfor(.....)
@html.textboxfor(.....)
....
<input type="submit" value="CreateAccount" class="buttonclass" title="CreateAccount" ; onclick="SaveUser(this);"
}
function SaveUser(btnClicked) {
alert("clear");
document.getElementById("regname").value = '';
document.getElementById("regusername").value = '';
document.getElementById("regemail").value = '';
document.getElementById("regpassword").value = '';
document.getElementById("regpassword2").value = '';
$.ajax({
url: window.location.pathname + '/Account/Logon',
type: 'GET',
})
.success(function (result) {
alert("user saved successfully");
});
UPDATE:
function SaveUser(btnClicked) {
document.getElementById("regname").value = '';
document.getElementById("regusername").value = '';
document.getElementById("regemail").value = '';
document.getElementById("regpassword").value = '';
document.getElementById("regpassword2").value = '';
alert('clear');
$.ajax({
type: "POST",
url: window.location.pathname + "Account/Register",
success: function (response) {
$.ajax({
url: window.location.pathname + '/Account/Logon',
type: 'GET',
})
.success(function (result) {
alert("user saved successfully");
// window.location ="";
});
},
error: function (xhr, status, error) {
alert("Failed");
}
});
}
I'm getting a Failed alert. Please help