Reputation: 4183
Inside my Index action I call my NotFound Action. I follow in debug and the if condition tests true, it goes to the "return RedirectToAction("NotFound");" statement, it then goes to Dispose and then returns to the Index Action not the NotFound Action. If I Redirect to the Details Action it works fine. These are all in the same controller. The NotFound View just contains text.
if (condition tests true) { return RedirectToAction("NotFound"); }
public ActionResult NotFound()
{ return View(); }
I've also tried the NotFound as a ViewResult. It still fails.
Upvotes: 0
Views: 745
Reputation: 218702
You can return the NotFound
View directly from your Index action
public ActionResult Index()
{
if(yourcondition)
{
return View("NotFound");
}
else
{
// Return the Index View.
return View();
}
}
This will work as long as there is a view named "NotFound.cshtml"
Upvotes: 1