2014-04-17 160 views
0

我使用路由這段代碼RouteConfig.cs配置asp.net的MVC路由

routes.MapRoute("Default", "", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); 

現在我想改變它,如果URL "<domain>/Saman/Profile",我應該加載個人資料頁面的用戶是username"Saman"

回答

0

其實你必須給予配置文件路由之前的默認route.here網址會查找配置文件,一旦它發現它會使用第一route.i希望這會工作。

routes.MapRoute(
      name: "Profile", 
      url: "FilesView/{name}", 
      defaults: new { controller = "FilesView", action = "Profile", name = UrlParameter.Optional } 
     ); 
routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "FilesView", action = "Index", id = UrlParameter.Optional } 
     ); 
+0

在您的解決方案的網址是這樣的: /資料/用戶 但我想,當URL是 /薩滿/ profile文件,搜索 「薩滿」 的用戶名,並獲得配置文件屬性。 –

+0

你可以嘗試添加{name} /Profile.here它會期望名稱/配置文件。 –

+0

我不認爲'name = UrlParameter.Optional'在這種情況下是好的。這裏真的應該是可選的嗎? – rosko