2011-09-27 3 views
0

리다이렉트를 사용하여 다른 페이지로 이동하는 것이 주목됩니다. 즉, 결과가 거짓 인 경우 예외가 발생하지 않은 페이지로 이동하고 싶습니다.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 호출의 성공 콜백에서 클라이언트 측에서 수행해야합니다.

success: function(result) { 
    if (result.errorUrl) { 
     window.location.href = result.errorUrl; 
    } else { 
     ... 
    } 
} 
: 당신의 AJAX 성공 콜백 내에서 다음

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

과 : 그 오류의 경우는 URL을 포함하는 JSON 객체로 리디렉션 반환 그래서 그래서 예를 들어, 당신은 당신의 행동을 적응 수

관련 문제