我想知道如何让ActionLink方法创建一个生成如下内容的链接:
/Home/Search/canon
而不是
/Home/Search?q=canon
如果ActionLink不能这样做,有没有人通过其他方式做过这个?
答案 0 :(得分:1)
在global.asax
中定义新路线RouteTable.Routes.Add(new Route
{
url="[controller]/[action]/[q]",
Defaultd=new{ action="Index", q=(string) null},
RouteHandler=typeof(MvcRouteHandler)
});
你的ActionLink世界就好了吗
@Html.ActionLink("Search", "Home", new { q = something })
会产生
/Home/Search/something
here是一个有用的链接