重命名控制器后未加载视图

View is not loading after renaming the controller

我将控制器从 homecontroller 更改为 ProfileController。 现在我的视图没有显示任何内容,但是当我将它从 Profilecontroller 改回 homecontroller 时,它再次正常工作。

我也改了:

 @using(Html.BeginForm("index", "homeController", FormMethod.Post, new { enctype = "multipart/form-data" }))

至:

@using(Html.BeginForm("index", "ProfileController", FormMethod.Post, new { enctype = "multipart/form-data" }))

如果您没有在控制器操作中明确指定视图,则 MVC 将使用视图查找约定 /Views/<ControllerName>/<ActionName>.cshtml:

/Views/Profile/Index.cshtml

在您的情况下,您还必须将文件夹 Home 重命名为 Profile

文档中的其他信息:
- https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/adding-a-controller
- https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/adding-a-view