I have the following Actionresult.
[HttpPost]
public ActionResult Logon(AdminModel model)
{
if (model.UserName == "x" && model.Password == "x")
{
Session["Authenticated"] = "true";
RedirectToAction("CreateBlog", "BlogController");
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
return View(model);
}
However when get to the RedirectToAction call the code carrys on until the View call and then complains that I have no Logon view. But I dont need one im using a ‘Index’ view to display the logon details and I just want the above to take me to another view. Am I missing something?
Well, return:
In ASP.NET MVC controller actions return action results. In your case you are simply calling the
RedirectToActionmethod but not returning its result. In your code sample the action executes up until it reaches the last line which of course returns a view instead of redirecting. You definitely want to stop the action execution and redirect immediately by returning the proper action result.