开发者

mvc route query

Im new to mvc and am playing with the albumstore tutorial. in my index view i have a loop like this.

@foreach (var genre in Model) {
    <li>@Html.ActionLink(genre.Name, "Browse", new { genre = genre.Name })</li>       
}

which results in the url http://localhost:59443/store/Browse?genre=Dicso

in my browse view i have simil开发者_开发知识库ar code

@foreach (var album in Model.Albums) {
    <li>@Html.ActionLink(album.Title, "Details", new { id = album.AlbumId })</li>
}

however this produces a url with the structure http://localhost:59443/store/Details/2

Can someone tell me why the structures are different using the same code. Thanks


Id is a special case because of the routing setup in global.asax.

In global.asax you will find something akin to this.

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜