我需要模擬對我有點奇怪的路線。這是他們想要我做的事情:如何在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" }
);
它只是感覺有點不對勁我。我錯過了處理東西的最佳做法嗎?這會導致什麼樣的問題呢?他們希望我製作的很多系統都是這樣工作的。
//編輯 如果這是一個不好的地方問這樣的問題,我應該問他們哪裏?
考慮想爲什麼「這只是感覺有點對我來說是錯誤的「,並且看看是否需要將更多信息添加到問題中......因爲您可以以任何方式設置路由(例如,所有在一個控制器上,所有單獨的,具有區域....)很難建議更好的路線,而不理解爲什麼這個不好。 –