我試圖用Html.ActionLink產生這種形式的鏈接:如何使用Asp MVC Url Helper生成RESTful鏈接?
/動作/型號/ ID /參數1 /參數2
我用: <%= Html.ActionLink("Link Text", "Action", "Model", new { id = var, parament1=var1 }, null) %>
但它總是結束看起來像/ Action/Model/Id?parameter1 =變量
我在Stackoverflow和其他地方看到過類似的問題,但我找不到解決方案。任何幫助,將不勝感激。
@約翰:我有以下途徑註冊:routes.MapRoute("Alternate","{controller}/{action}/{id}/{Heading}", new { controller = "Designation", action = "Details", id = "", Heading = "" }
I then have the following code in my view: <%= Html.ActionLink("Link Text", "Action", "Model", new { Id = model.Id, Heading = model.Heading }, null) %>
我獲得/型號/動作/編號標題= VAR1我想把它當作/型號/動作/ ID/VAR1
回答:我將以下路由添加到我的global.asax.cs文件並正確生成鏈接。 routes.MapRoute(「Something」,「MyModel/MyAction/{Id}/{Heading}」,new {controller =「MyModel」,action =「MyAction」,id =「」,heading =「」},new { controller = @「[^。] *」});
你已經註冊在Global.asax你的路由支持/動作/控制器/ ID /參數1 /參數2?默認情況下,在Global.ASAX中註冊的路由是/ Controller/Action/id,並且輸入的所有其他參數都位於QueryString中。 – 2010-04-14 21:38:42