开发者

ASP.NET MVC routing problem?

Why does:

<%= Html.ActionLinkForAreas<UsersController>(c => c.User(), "My Details") %>

Generate an URL containing this:

Users/User

But:

开发者_JS百科<%= Html.ActionLinkForAreas<BlaController>(c => c.Index(1), "My Bla Di Bla")%>

An URL like this:

Bla

Rather than this:

Bla/Index

In other words why is the Index action ‘swallowed’. Does this have to do with the routing which looks like this:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

routes.RouteExistingFiles = true;
routes.IgnoreRoute("Content/{*wildcard}");
routes.IgnoreRoute("Scripts/{*wildcard}");

routes.MapRoute(
"Default",                                              // Route name
"{controller}/{action}/{id}",                           // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }  // Parameter defaults
);

Or is there another reason? How can I change this behaviour? Thanks.

Best wishes,

Christian


Becaues you've specified Index as your default action:

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }  // Parameter defaults
);

The action = "Index" part. Since it's the default action, whenever your create URLs to it, the "Index" part will be omitted. This affords you the opportunity to have nice concise URLs. Incidentally, the same rule applies to the controller itself. If you route to the "Home" controller, URLs to it will have the "Home" part elided, thus allowing you to have a raw base URL such as "/".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜