# InvalidOperationException: 未找到视图'Index'。已搜索以下位置：/Views/Home/Index.cshtml, /Views/Shared/Index.cshtml, /Pages/Home/Index.cshtml

- **ID:** `dotnet/razor-pages-view-engine-missing-file`
- **领域:** dotnet
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

Razor视图引擎无法找到指定的视图文件，因为文件缺失、路径不正确或视图未编译（例如由于缺少@page指令或文件夹结构错误）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| .NET 6.0 | active | — | — |
| .NET 7.0 | active | — | — |
| .NET 8.0 | active | — | — |
| ASP.NET Core MVC 6.0+ | active | — | — |
| Razor Pages 6.0+ | active | — | — |

## 解决方案

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.
   ```
2. ```
   If using Razor Pages, ensure the page is in /Pages folder and has an @page directive at the top, with a matching route.
   ```

## 无效尝试

- **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% 失败率)
- **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% 失败率)
