0

I've been working on this problem for a while now and I'm not sure what else to try. The error message I'm getting is this:

System.InvalidOperationException: The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml

The view is located at Views/Home/Index.cshtml

Here's the RouteConfig class

public class RouteConfig {  
  public static void RegisterRoutes(RouteCollection routes) {
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
      name: "Default",
      url: "{controller}/{action}/{id}",
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
  }
}

Even putting a breakpoint in the Index action on the Home controller doesn't trigger. The Index controller action just returns the view:

public ActionResult Index() {
  return View("~/Views/Home/Index.cshtml");
}

The project settings are set to Use Local IIS Web server

Web settings for project

Building the project succeeds. There are no build events. Target framework is .NET Framework 4.5. Output type is Class Library.

I was comparing everything I could think of with another project that is working and there's nothing standing out to me. I even compared the .csproj files of both and the only differences seemed to be <Content Include lines for files that are not in the other project. Any ideas on where to look next to fix this?

David Starkey
  • 1,840
  • 3
  • 32
  • 48
  • This might be silly but are you making sure you're in debug when running and not release? – Michael Puckett II Jun 11 '18 at 15:47
  • 1
    @MichaelPuckettII At this point, I'll accept all the "might be silly" questions because I've got to be missing something. To answer your question, yes it is in debug config. Just because, I also tried in Release config, same error. – David Starkey Jun 11 '18 at 15:54

3 Answers3

2

You should just say return View("Index"); or just return View(); It would search for a view with the same name as of action method

Rahul
  • 76,197
  • 13
  • 71
  • 125
1

Try right clicking on your index.cshtml and select Properties. In the properties window set the Build Action to Content. This may solve your problem.

Also verify you have the _Layout.cshtml file in the shared folder if your _ViewStart.cshtml points to that.

Ajay Gupta
  • 1,775
  • 1
  • 10
  • 22
1

After deciding to stop focusing on the error and start focusing on why breakpoints were not being hit, I found myself at this answer

Ok so after 4 hours wasted, I find that setting my web project as the startup project solves the issue! This surely must be a bug...

I hope I save someone out there half a day :)

Turns out the website project was not set as the startup project. Unfortunately, other answerer, I still ended up spending way to long figuring that out.

Community
  • 1
  • 1
David Starkey
  • 1,840
  • 3
  • 32
  • 48