所有,我的情況是,我的基本路線,加上其他一些簡單的路線:如何添加一個url參數到asp.net mvc中的routelink?
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = 1}
);
所以下面的網址工作:http://somesite.com/tags/index/1
不過,我的一些索引頁的採取URL參數以下列方式:
http://somesite.com/tags/index/1?when=lastmonth
如何使用Html.RouteLink鏈接到此?
您不能 add'?'在全球ASAX文件的路線是這樣的:
routes.MapRoute("TagsWhen", "Tags/index/{id}?when={when}",
new {controller = "Tags", action = "Index", id = "", when = ""});
如果這條線路的工作,我可以用鏈接到它:
Html.RouteLink(string.Format("{0} ", link.Rating), "LinksWhen",
new {id=link.ReferenceId, when=Model.When})
,但它不會!所以我不知道我怎麼會用一個Html.RouteLink產生http://somesite.com/tags/index/1?when=lastmonth
但不會產生不正確的網址? – 2009-05-03 20:02:33
剛試過這個,它生成: http://somesite.com/tags/index?when=lastmonth 並沒有添加id ... – 2009-05-03 20:10:21