2012-01-01 59 views
1

我不知道我怎样才能使ActionLink的方法创建生成类似的链接在MVC创建搜索引擎友好链接:如何使用ActionLink的

/Home/Search/canon 

,而不是

/Home/Search?q=canon 

如果ActionLink的不能那么,有没有人通过其他方式做过这件事?

+0

询问很多次之前..... – 2012-01-01 11:40:40

+0

请阅读问题。也许这不是你的想法! – 2012-01-01 11:54:27

+0

人们可能会感到困惑,因为标题的... – rene 2012-01-01 11:57:23

回答

1

在global.ascx

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是一个有用的链接