2011-09-27 23 views
0

我知道naviagate到另一个页面使用重定向即当结果为false,那么我想导航到异常页面,这是不会发生。无法导航使用RedirectToAction

public ActionResult IsLoginExsit(CustomerDO loginData) 
    {   


     if (!string.IsNullOrEmpty(loginData.UserName) && !string.IsNullOrEmpty(loginData.Password)) 
     { 
      bool result = Businesss.Factory.BusinessFactory.GetRegistrations().IsLoginExist(loginData.UserName, loginData.Password); 
      if (result) 
      { 
       CustomerDO custInfo = new CustomerDO(); 
       JsonResult jsonResult = new JsonResult(); 
       jsonResult.Data = loginData; 
       custInfo = Businesss.Factory.BusinessFactory.GetRegistrations().GetCustInfoByUserName(loginData.UserName); 
       SessionWrapper.SetInSession("CustomerID", custInfo.Id); 
       SessionWrapper.SetInSession("CustomerFirstName", custInfo.FirstName); 
       SessionWrapper.SetInSession("CustomerLastName", custInfo.LastName); 
       return jsonResult; 
      } 
      else 
      { 
       return RedirectToAction("UnAuthorized", "Exceptions"); 
      } 
     } 
     return View(); 

    } 

回答

0

您似乎在使用AJAX调用此操作。如果你想重定向,应该在客户端使用window.location.href进行此AJAX调用的成功回调。

else 
{ 
    return Json(new { errorUrl = Url.Action("UnAuthorized", "Exceptions") }); 
} 

,然后你的AJAX成功回调中:

success: function(result) { 
    if (result.errorUrl) { 
     window.location.href = result.errorUrl; 
    } else { 
     ... 
    } 
} 
因此,例如,使错误的情况下,它返回一个包含URL JSON对象重定向到你能适应你的行动