Problem
Hi, I'm trying to redirect to a different action in my controller when a
Department
can't be found. My problem is that it does not redirect immediately after I hit the code block. I'm not sure if it is the correct method to use for this, but to me it seemed like it should work. I would also prefer not using Response.Redirect(url);
because that just seems a bit messy to me.
Code
if(errors.Count > 0)
{
RedirectToAction("Index", "Department"); //Redirect to the index page, because the department could not be found
}
Additionally
Is there also a nice way to send an error to the
Index()
action? Would/Could/Should I do that with a viewbag for instance, or is that really only for the views?
Thanks in advance.