问题描述
请解释。
当我默认在MVC中创建一个新视图时,我正在获取索引页面。我想根据我显示视图的名称。当我重命名索引视图时,它通过错误。请解释相同的
Please explain.
When i create a new view in MVC by default i am getting Index page. I want to display the name of view according to me. When i rename Index view its through error. Please Explain the same
推荐答案
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
因此,如果您没有指定一个动作名称,它将使用索引
。除了重命名操作方法之外,这是您需要更改的内容。当然,你还需要准备好适当的视图(* .cshtml)。
所以假设你想要 startpage
而不是 index
。您需要执行以下操作:
1)更改从索引到首页的默认路由
2)将索引方法重命名为控制器中的startpage
3)将index.cshtml重命名为startpage.cshtml
如果从裸应用程序开始,则只需要步骤1,然后继续执行操作。
So if you don't specify an action name it will use Index
. This is what you need to change in addition to renaming the action method. And of course, you need also to have proper views prepared (*.cshtml).
So let's say you want startpage
instead of index
. You need to do followings:
1) change the default route from index to startpage
2) rename index method to startpage in the controller
3) rename index.cshtml to startpage.cshtml
If you start with bare application, you need only step 1, and proceed with the actions.
这篇关于如何更改控制器索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!