开发者

not able to navigate using RedirectToAction

I am notable to naviagate to another page using Redirect ie when result is false, then i would like to navigate to exception page which is not happening.

 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();

    }


You seem to be invoking this action using AJAX. If you want to redirect this should be done on the client side in the success callback of this AJAX call using window.location.href. So for example you could adapt your action so that in case of error it returns a JSON object containing the url to redirect to:

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

and then inside your AJAX success callback:

success: function(result) {
    if (result.errorUrl) {
        window.location.href = result.errorUrl;
    } else {
        ...
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜