I called ActionResult from javascript as below:
function checkSessionNewContribute(){
if (@MountainBooks.Common.ProjectSession.UserID != 0) {
window.location.href = "../Book/ContributeNewBook"
}
else{
$.ajax({
url: "@Url.Action("redirectToLogin", "Home")"
});
}
}
I need to pass TempData from this ActionResult:
public ActionResult redirectToLogin(){
TempData["Login"] = Resource.Messages.LoginRequired;
return RedirectToAction("Index","Login");
}
This is my Index Action:
public ActionResult Index() {
string email = null;
string password = null;
if (Request.Cookies["Login"] != null){
email = Request.Cookies["Login"].Values["LogedEmail"];
password = General.DecryptCipherTextToPlainText(Request.Cookies["Login"].Values["LogedPwd"]);
}
ViewBag.ErrorMessage = TempData["wrongPassword"];
ViewBag.Login = TempData["Login"];
UserModel userModel = new UserModel();
userModel.Email = email;
userModel.Password = password;
ViewData["LoginModel"] = userModel;
userModel = new UserModel();
userModel.Occupations = (_occupationService.GetAllOccupation());
ViewData["RegisterModel"] = userModel;
return View();
}
Index action is getting called, debugger also goes into the .cshtml file which Index Action returns as View(), but the page is not getting redirected. Is it because I used $.ajax() ? Is there another way to do this?