开发者

Simple Html.Actionlink question (MVC3)

The Route:

            routes.MapRoute(
            "Items", // Route name
            "{controller}/{action}/{id}", // URL with开发者_如何学编程 parameters
            new {controller = "Item", action = "Index", id = UrlParameter.Optional} // Parameter defaults
            );

The htmlhelper:

@Html.ActionLink("Chairs", "List", "Item", new {id="Chairs"}, null)

The link it generates:

http://localhost:57899/Item/List?id=Chairs

What I want it to show:

 http://localhost:57899/Item/List/Chairs

How to do that?


Instead of using ActionLink what happens if you try the following?

@Html.RouteLink("Items", new { id = "Chairs" })


You call Html.RouteLink (not Action Link) and map an additional route under your generic like this:

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

when you call RouteLink, you'll simply pass that "ChairsRoute" name

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜