JscNZ JscNZ - 1 year ago 230
C# Question

MVC 5 - RedirectToAction Not Redirecting

Hi I have a problem with my RedirectToAction not redirecting. My code successfully hits a breakpoint placed on the Redirect so I can confirm it is being called. Nothing seems to happen however.

I have tried looking at the network traffic in Chrome and there doesn't seem to be anything obvious. I must be missing something simple!

//
// POST: /Blog/CreateBlog
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CreateBlog(BlogViewModel model)
{
var userId = User.Identity.GetUserId();
model.UserId = userId;

if (ModelState.IsValid && model.UserId != null)
{
Mapper.CreateMap<BlogViewModel, Blog>();
if (_blogProcess.CreateBlog(Mapper.Map<BlogViewModel, Blog>(model)))
{
RedirectToAction("Index", "Blog");
}
}

// If we got this far, something failed, redisplay form
return View(model);
}

Answer Source

try

return RedirectToAction("Index", "Blog");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download