'The view 'name' or its master was not found or no view engine supports the searched locations

I'm getting this error message, and any of the advice that I've seen does not appear to be applicable; i.e. all views, controllers and models are in the correct folders.

More detail: I have a master view, which shows a graphical flowchart-like interface for interacting with the application. The user selects the "Open Study" symbol, and I redirect to another view which allows the user to select a Study to work with.

The OpenStudyController code retrieves the selected study and then redirects back to the master view:

public ActionResult SelectStudy( Guid? id )
{
    // code elided for clarity

    return RedirectToAction( "ActivateStudy", "Home" );
}

HomeController has a method called ActivateStudy(...), which does get invoked with the appropriate environment:

public ActionResult ActivateStudy()
{
    // code elided for clarity

    return View();
}

As I said, all views, controllers and models are in the correct folders.

When the "return View()" code in ActivateStudy() is executed, the error message occurs:

Server Error in '/' Application.

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

What am I missing? Some additional parameter in RedirectToAction(...)? Some new entry in RouteConfig?



Solution 1:[1]

If you have a _ViewStart.cshtml and it contains something like the following you do not need to specify the same layout in each view.

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

I believe your problem might be related to a missing slash. In your comment you said that your view contained the following line:

Layout = "~Views/Shared/_Layout.cshtml"

I think that needs to have a slash after the tilde.

Layout = "~/Views/Shared/_Layout.cshtml"

But, as I said, you should be able to remove that line entirely.

Solution 2:[2]

Well, I don't know if this is the "right" way to do it, but, in my HomeController.ActivateStudy() method, I return the Home "index" view:

public ActionResult ActivateStudy()
{
    // code elided for clarity

    return View( "Index" );
}

And this works.

It's at times like these where you realize you really don't know very much. Back to the books and code editor. Learn by doing.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Craig W.
Solution 2 kmontgom