简体   繁体   English

ASP.NET MVC更改了视图名称

[英]ASP.NET MVC changed view name

I changed the name of view files (Index.cshtml -> Performance.cshtml), and when I execute the project, the application can't recognise the new view name. 我更改了视图文件的名称(Index.cshtml-> Performance.cshtml),并且在执行项目时,应用程序无法识别新的视图名称。 I changed the name of an action in controller accordingly (ActionResult Index() -> ActionResult Performance()). 我相应地更改了控制器中的动作名称(ActionResult Index()-> ActionResult Performance())。 However, it keeps saying HTTP 404 error. 但是,它一直说HTTP 404错误。

Change the default route defined in App_Start/RouteConfig.cs file to set Performance as the default action. 更改App_Start / RouteConfig.cs文件中定义的默认路由,以将“性能”设置为默认操作。

Or, you can run the project with the following URL: http://localhost:port/home/Performance 或者,您可以使用以下URL运行项目: http://localhost:port/home/Performance

When you change your view name mvc application can't find a proper view for it's controller action method. 当您更改视图名称时,mvc应用程序无法为其控制器操作方法找到正确的视图。

If it is your default page view( load on application start) than you also need to make changes in your Route_config file. 如果这是您的默认页面视图(在应用程序启动时加载),则还需要在Route_config文件中进行更改。
See the image below 见下图 在此处输入图片说明 Change controller = " Name_of_controller" & action="name_of_action" in your case action name will be Performance . 在您的案例中,将controller = " Name_of_controller"action="name_of_action"更改为Performance
Always Remember in mvc you can run any method using browser url 永远记得在mvc中,您可以使用浏览器网址运行任何方法
for example : controller is home & method is Performance than url will be localhost:port/home/Performance 例如 :控制器是home&方法是Performance,而url将是localhost:port / home / Performance

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM