Scuba Steve Scuba Steve - 3 years ago 143
ASP.NET (C#) Question mvc 5 - system doesn't find a view that exists

So here's the code that's running:

return RedirectToAction("BadFileError", "Error");

Which then redirects the viewer to:


Which exists in
enter image description here

What on earth am I missing here? Why can't seem to see views that I create without using the scaffolding system?
Here's the error it throws:
enter image description here

Answer Source

Your browser will make a request to yourSite/Error/BadFileError and aspnet mvc framework will not directly serve the razor file.

You need to have an action method with that name in your ErrorController. The request will be directed to the action method, not to the view file. Your action method can return that view (or any other view)

Add this to the ErrorController.

public ActionResult BadFileError()
   return View();

Also, If you simply want to show the error view content to the user, you can do that with the View() method call with the full path to your error view. You do not necessarily need to do a redirect(which will issue a new http request).

So instead of the redirect, you can do

return View("~/Views/Error/BadFileError.cshtml");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download