如何更改控制器索引 [英] How to change controller Index

查看:116
本文介绍了如何更改控制器索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请解释。



当我默认在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

推荐答案

命名您的行动取决于您。但是你必须相应地设置路由。

阅读本文: http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs [ ^ ]

正如您将看到的,有一个默认的路线映射:

Naming your actions is up to you. But you have to set up routing accordingly.
Read this article: http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs[^]
As you will see, there is a default route mapping:
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.


这篇关于如何更改控制器索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆