900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > .net mvc ajax重定向 如何在MVC3 JQuery的Ajax调用重定向到新的页面(连同模型)(How to redirec...

.net mvc ajax重定向 如何在MVC3 JQuery的Ajax调用重定向到新的页面(连同模型)(How to redirec...

时间:2023-06-22 09:43:06

相关推荐

.net mvc ajax重定向 如何在MVC3 JQuery的Ajax调用重定向到新的页面(连同模型)(How to redirec...

我已经忘记密码页面,当用户输入用户名并点击“验证”按钮来检查他是在哪个组的基础上,我们需要显示不同的局部视图(现在让我们说,这是电话号码)的组这一页。 填写有效信息后, 成功我会重定向到一个新的页面,在那里他将更新自己的密码,如果失败,我需要显示错误消息。

现在,我在写代码的突出困难时期。

这里是一个触发提交按钮点击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();

}

}

请帮忙。 提前致谢

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。