我有一个注册表单,成功注册后,它会重定向到另一个视图。我使用提交按钮将数据插入数据库,我想清除当前视图中的值并将用户重定向到logon page
同一控制器下的另一个视图中。提交类型未执行 jquery 中提到的操作。请帮助我
这是我的代码预览
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");
});
更新:
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");
}
});
}
我收到失败警报。请帮忙