在VS 2010中更改默认视图 [英] Change default view in VS 2010
问题描述
如何设置更改MVC3默认视图debbuging在Visual Studio 2010中的项目时
How to set change a default View in MVC3 when debbuging the project in Visual Studio 2010.
一旦我打了F5,默认视图它打开为localhost /首页/索引。
As soon I hit F5, The default View it opens is Localhost/Home/Index.
它在哪里被设置,我该如何更新?
Where is it being set, How do I update it?
任何人都可以提供一些线索对这个好吗?它不是简单的(对我来说虽然)。
Can anyone shed some light on this please? It is not straight forward(for me though).
感谢您
推荐答案
所有你需要做的就是改变你的默认图路线
参数。通常,这是什么,你会看到的默认的作为你的默认
路线:
All you have to do is changed your default MapRoute
parameters. Typically, this is what you'll see by default as your Default
route:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home",
action = "Index",
id = UrlParameter.Optional }); // Parameter defaults
只要改变控制器
属性和动作
属性,你希望你的默认是什么。例如,你可以这样做:
Just change the controller
property and the action
property to what you want your default to be. For instance, you could do:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "AnotherController",
action = "aDifferentAction",
id = UrlParameter.Optional }); // Parameter defaults
所有这一切都在这里改变的是控制器
和操作
属性。现在,当您浏览到刚刚合格的名字,它会去你的 AnotherController.aDifferentAction()
方法,而不是 HomeController.Index()
方法。
All that is changed here is the controller
and action
properties. Now when you browse to just the qualified name, it will go to your AnotherController.aDifferentAction()
method, instead of the HomeController.Index()
method.
之所以默认为 Home.Index()
,是因为这是当你有空路由参数的第一个匹配的路由控制器
和操作
。通过更改图路线()
调用这些默认值,你是在告诉路由,如果没有什么是那里的路由参数,转到 AnotherController.aDifferentAction( )
操作方法。
The reason why it defaults to Home.Index()
, is because that is the first matched route when you have empty route parameters for controller
and action
. By changing these defaults in the MapRoute()
call, you are telling routing that if nothing is there for the route parameters, go to AnotherController.aDifferentAction()
action method.
只要这是第一路线,则应该设置
As long as this is the first route, you should be set.
这篇关于在VS 2010中更改默认视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!