我忘记了密码页面,用户在其中输入用户名并单击“验证”按钮来检查他所在的组。根据组,我们需要显示不同的部分视图(现在假设它是电话号码)这一页。填写有效信息后,如果成功,我将重定向到一个新页面,他将在其中更新他的密码;如果失败,我需要显示错误消息。
现在我很难编写突出显示的代码。
这是 Jquery ajax 函数的代码,该函数在单击提交按钮时触发
person = {UserName: $("#UserName").val(), Phone: $("#Phone").val() }
$.ajax({
type: 'POST',
url: '@Url.Action("ForgotPassword", "Customer")',
data: person,
dataType: 'json',
success: function (data) {
//This is the place I need help
if(data.IsDataValid){
// redirect to new page passing the model object
}
else{
//Show an error message without hiding the div
}
},
failure: function () {
}
});
这是控制器操作的代码
[HttpPost]
[ValidateInput(true)]
public ActionResult ForgotPassword(RegisterModel model)
{
if (Request.IsAjaxRequest())
{
Here is the logic which validates the user
return Json(new { regmodel = RegistrationModel })
}
//If it is not ajax call I want to return the view
if (isUsergroup1 == true)
{
return View("View1", RegistrationModel );
}
else if (isUsergroup2 == true)
{
return View("View2", RegistrationModel );
}
else
{
return View();
}
}
请帮忙。提前致谢
这就是我们需要做的。我们无法传递模型,只能传递链接重定向中的参数。我们必须使用 link.replace 因为你可以将变量直接传递到 Url.Action 中
person = {UserName: $("#UserName").val(), Phone: $("#Phone").val() }
$.ajax({
type: 'POST',
url: '@Url.Action("ForgotPassword", "Customer")',
data: person,
dataType: 'json',
success: function (data) {
//This is the place I need help
if(IsDataValid){
var link = "@Url.Action("Actionname", "Controllername", new { username = "1", phone ="2" })";
link = link.replace("1", data.username);
link = link.replace("2", data.phone);
alert(link);
window.location.href= link ;
}
else{
//Show an error message without hiding the div
}
},
failure: function () {
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)