2012-11-14 171 views
0

我需要模擬對我有點奇怪的路線。這是他們想要我做的事情:如何在ASP.NET MVC 3中建模此路線?

/AssetManagement -> Asset Landing page 
/AssetManagement/Add -> Add an asset 
/AssetManagement/Edit -> Edit an asset 
/AssetManagement/Locations -> Locations landing page 
/AssetManagement/Locations/Add -> Add a location 
/AssetManagement/Locations/Edit -> Edit a location 

我不確定,但我認爲這需要用兩個控制器建模。 AssetsController和LocationsController。我認爲意見添加/編輯/索引下,尊重查看文件夾會存在,我可能會有兩種途徑定義爲:

routes.MapRoute(
    "AssetManagement", // Route name 
    "AssetManagement/{action}/{id}", // URL with parameters 
    new { controller = "Assets", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
    new[] { "MyApplication.Web.Website.Controllers" } 
); 

routes.MapRoute(
    "AssetManagementLocations", // Route name 
    "AssetManagement/{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Locations", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
    new[] { "MyApplication.Web.Website.Controllers" } 
); 

它只是感覺有點不對勁我。我錯過了處理東西的最佳做法嗎?這會導致什麼樣的問題呢?他們希望我製作的很多系統都是這樣工作的。

//編輯 如果這是一個不好的地方問這樣的問題,我應該問他們哪裏?

+0

考慮想爲什麼「這只是感覺有點對我來說是錯誤的「,並且看看是否需要將更多信息添加到問題中......因爲您可以以任何方式設置路由(例如,所有在一個控制器上,所有單獨的,具有區域....)很難建議更好的路線,而不理解爲什麼這個不好。 –

回答

1

你可以做的是創建一個區域。

在該區域創建2個控制器,一個用於資產,另一個用於位置。

與MVC概念一起玩的路線(這可能是危險的),而不是玩。

您指定的第二條路線與地區密切相關。 當您創建區域時,會自動爲您創建路線。 希望這有助於。

Area - AssetManagement 
    Controller1 - HomeController 
       Action1 - Add 
       Action2 - Delete 

    Controller2 - LocationsController 
       Action1 - Add 
       Action2 - Delete 

routes.MapRoute(
    "AssetManagementLocations", // Route name 
    "{Area}/{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Locations", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
    new[] { "MyApplication.Web.Website.Controllers" } 
);