2013-04-16 24 views
0

我有一個名爲User的面積,我寫圖路線吧:ASP.NET MVC 2 - 如何在Context.MapRoute中修改Url屬性以寫入RouteUrl?

context.MapRoute(
     "User_Category", 
     "User/Category/{categoryId}", 
     new { controller = "Product", action = "Category", categoryId = UrlParameter.Optional }, 
     new { categoryId = @"\d+" } 
); 

這是另一個例子,我有一個鏈接:

<%=Html.ActionLink("Điện thoại", "Category", new { area = "User", controller = "Product", id = 1 }, null) %> 
(http://localhost:8578/User/Product/Category/1) 

當然,我不能做到這一點:

<%=Html.ActionLink("Điện thoại", "User/Category", new { area = "User", controller = "Product", id = 1 }, null) %> 

以下MapRoute以上,它被修改。這意味着,它在一個地區的,我不知道如何通過區域名稱到ActionLink的有:http://localhost:8587/User/Category/1

但我要的東西是代替ActionLink應該RouteUrl得到像絕對鏈接**http://localhost:8587/User/Category/1**

我該怎麼辦?而我如何刪除用戶名稱的網址?感謝觀看!

回答

1

我認爲這是因爲您的路線是使用路線參數categoryId定義的,但您的操作鏈接僅使用參數id?如果是的話,試試這個來代替:

<%=Html.ActionLink("Điện thoại", "Category", new { area = "User", controller = "Product", categoryId= 1 }, null) %> 

如果你想完整的絕對URL,那麼你可以這樣做:

<a href="<%= Html.ViewContext.HttpContext.Request.Url.GetLeftPart(UriPartial.Authority) + Url.Action("Category", new { area = "User", controller = "Product", categoryId= 1 }) %>">Điện thoại</a> 
+0

@lan勞特利奇:謝謝!但我給了ActionLink來證明這一點,我想知道如何在絕對鏈接(RouteUrl)中顯示鏈接名稱(「Điệnthoại」),其中包括區域名稱。 –

+0

我已經更改了答案,以包含絕對URL的詳細信息 –

+0

好的!我現在會嘗試。 –