2016-03-22 48 views
1

在我的ASP.Net MVC應用程序,我已經改變了默認路由登記startup.cs到獲取網址在asp.net mvc的自定義路由

routes.MapRoute(
    name: "default", 
    template: "{customer}/{language=fi-FI}/{controller=Home}/{action=Index}/{id?}"); 

因此,所有的路線將包含客戶ID和當前語言。自定義段匹配需要投入新的網址,客戶和語言信息的照顧,所以當所請求的網址/ customer1表/ FI-FI/somecontroller/someaction這樣

<a asp-controller="othercontroller" asp-action="otheraction">Some action</a> 

任何生成的URL會正確地與客戶生成和語言代碼。

問題是,我應該如何生成url,以便我可以指定客戶端和語言代碼而無需進行字符串連接?我需要這個例如在改變語言的鏈接中。

我已經試過

<a asp-controller="somecontroller" asp-action="someaction" asp-route="default" asp-route-customer="customer2" asp-route-language="en-us">Some action in other language and other customer</a> 

但表示,被定義ASP的路線時,我不能指定動作和控制器,如果我遠程ASP-航線再沒有什麼變化。

+0

我在這個項目中,支持文件夾的租戶,https://github.com/joeaudette/cloudscribe我認爲你需要實現{}客戶的路由約束,因爲我已經爲SiteFolder做類似的東西。請參閱示例Web應用程序項目中的啓動 –

回答

0

我通過使用@ Url.RouteUrl(例如,

@Url.RouteUrl("default", new { customer = "someothercustomer", language = "someotherlanguage", controller = "somecontroller", action = "someaction" })