问题描述
- asp.net mvc ajax跳转?
-
控制器里面有一个Get action ,一个Post action,如下
///
/// 手提電話驗證頁面
///
///
[AuthorizeFilterAttribute]
public ActionResult ValidatePhone()
{
return View();
}/// <summary> /// 手提電話驗證Post方法 /// </summary> /// <returns></returns> [HttpPost] [AuthorizeFilterAttribute] public ActionResult ValidatePhone(string validateCode) { 代码略 } 两者都是要求要登陆的(代码里面需要获取用户信息等信息),写了一个ActionFilter: public class AuthorizeFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var controller = (filterContext.Controller as BaseController); if (controller == null) { throw new NotImplementedException(filterContext.Controller.GetType().FullName); } else { if (controller.NeedLogin) { if (controller.IsLogin) { base.OnActionExecuting(filterContext); } else { filterContext.Result = new RedirectResult(“登陆首页URL”); } } else { base.OnActionExecuting(filterContext); } } } }, Get action可以正常跳转到登陆页面,但是假如页面打开1小时之后再点击按钮发送post请求,filter刚好获取到未登陆(超过了登陆持续时间),那这样该怎么跳转呢? 那个filterContext.Result 都是属于ajax请求的返回信息,跪求大神。。。
解决方案
返回json,包含url,然后在客户端跳转
解决方案二:
返回错误码 用js 刷新页面.
解决方案三:
ASP.NET MVC中的页面跳转
ASP.NET MVC中的页面跳转
Asp.net MVC 中Ajax的使用
时间: 2024-08-30 00:54:33