# InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Home/Index.cshtml, /Views/Shared/Index.cshtml, /Pages/Home/Index.cshtml

- **ID:** `dotnet/razor-pages-view-engine-missing-file`
- **Domain:** dotnet
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The Razor view engine cannot locate the specified view file because the file is missing, the path is incorrect, or the view has not been compiled (e.g., due to a missing @page directive or incorrect folder structure).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| .NET 6.0 | active | — | — |
| .NET 7.0 | active | — | — |
| .NET 8.0 | active | — | — |
| ASP.NET Core MVC 6.0+ | active | — | — |
| Razor Pages 6.0+ | active | — | — |

## Workarounds

1. **Create the missing view file at the correct location: /Views/{ControllerName}/{ActionName}.cshtml (e.g., /Views/Home/Index.cshtml) with the required Razor content.** (95% success)
   ```
   Create the missing view file at the correct location: /Views/{ControllerName}/{ActionName}.cshtml (e.g., /Views/Home/Index.cshtml) with the required Razor content.
   ```
2. **If using Razor Pages, ensure the page is in /Pages folder and has an @page directive at the top, with a matching route.** (85% success)
   ```
   If using Razor Pages, ensure the page is in /Pages folder and has an @page directive at the top, with a matching route.
   ```

## Dead Ends

- **Adding a view file with the same name but in a different folder (e.g., /Views/Shared/Index.cshtml instead of /Views/Home/Index.cshtml)** — The view engine searches specific locations based on controller name; a shared view may not be picked up if the controller expects a specific view. (50% fail)
- **Setting the view location format in Startup.cs to include custom paths without ensuring the actual file exists** — The custom path is searched, but if the file is still missing, the error persists. (30% fail)
