Hi All,
I have a catch-all route setup in ASP.NET MVC, so I can capture /this-page, /that-page etc.
When you hit a page the action is invoked, say Index(string page)
and then page
is tested against a value in the database to determine if the page can be found. If it can't be found, I want to display the view FileNotFound
which is in my ErrorController
, I do not want to redirect as I want to keep the url as http://.../page-that-isnt-found, exactly like StackOverflow does in fact if you give it a bogus question - (http://stackoverflow.com/questions/zzz-aaa).
Now my problem lies with figuring out the code, I have tried both:
[ do page db check ]
if (page == null)
return RedirectToAction("FileNotFound", "Error");
// return View("FileNotFound"); // can't opt for a controller ?
The closest I get is with RedirectToAction()
, however of course it does an actual redirect, and my url is pointed at /error which is not desired behaviour. I have tried using return View()
but it seems I can't specify a controller, only the view name?