[Route("")] public ActionResult Index() { = CleanIDs(); return View(); } [Route("Department/{departmentId}")] public ActionResult DepartmentById(int departmentId) { = CleanIDs(); ViewBag.departmentId = departmentId; return View("Index"); } [Route("Category/{categoryId}")] public ActionResult CategoryById(int categoryId) { = CleanIDs(); ViewBag.categoryId = categoryId; return View("Index"); } [Route("Item/{itemId}")] public ActionResult ItemById(int itemId) { = CleanIDs(); ViewBag.itemId = itemId; return View("Index"); } [Route("SubCategory/{subCategoryId}")] public ActionResult SubCategoryById(int subCategoryId) { = CleanIDs(); ViewBag.subCategoryId = subCategoryId; return View("Index"); } public CleanIDs() { ViewBag.departmentId = 0; ViewBag.categoryId = 0; ViewBag.itemId = 0; ViewBag.subCategoryId = 0; return ; }
[Route("")] public ActionResult Index() { = CleanIDs() return View(); } [Route("Department/{departmentId}")] public ActionResult DepartmentById(int departmentId) { return ByID("departmentId", departmentId); } [Route("Category/{categoryId}")] public ActionResult CategoryById(int categoryId) { return ByID("categoryId", categoryId); } [Route("Item/{itemId}")] public ActionResult ItemById(int itemId) { return ByID("itemId", itemId); } [Route("SubCategory/{subCategoryId}")] public ActionResult SubCategoryById(int subCategoryId) { return ByID("subCategoryId", subCategoryId); } public ActionResult ByID(string key, int value) { = CleanIDs() ViewBag[key] = value; return View("Index"); } public CleanIDs() { ViewBag["departmentId"] = 0; ViewBag["categoryId"] = 0; ViewBag["itemId"] = 0; ViewBag["subCategoryId"] = 0; return ; }but it is easy to see that most of the individual routing functions can be eliminated if the call is done directly to ByID with the correct parameters.
> [Route("")] > public ActionResult Index() > { > ViewBag.departmentId = 0; > ViewBag.categoryId = 0; > ViewBag.itemId = 0; > ViewBag.subCategoryId = 0; > return View(); > } > > [Route("Department/{departmentId}")] > public ActionResult DepartmentById(int departmentId) > { > ViewBag.departmentId = departmentId; > ViewBag.categoryId = 0; > ViewBag.itemId = 0; > ViewBag.subCategoryId = 0; > return View("Index"); > } > > [Route("Category/{categoryId}")] > public ActionResult CategoryById(int categoryId) > { > ViewBag.categoryId = categoryId; > ViewBag.departmentId = 0; > ViewBag.itemId = 0; > ViewBag.subCategoryId = 0; > return View("Index"); > } > > [Route("Item/{itemId}")] > public ActionResult ItemById(int itemId) > { > ViewBag.categoryId = 0; > ViewBag.departmentId = 0; > ViewBag.itemId = itemId; > ViewBag.subCategoryId = 0; > return View("Index"); > } > > [Route("SubCategory/{subCategoryId}")] > public ActionResult SubCategoryById(int subCategoryId) > { > ViewBag.categoryId = 0; > ViewBag.departmentId = 0; > ViewBag.itemId = 0; > ViewBag.subCategoryId = subCategoryId; > return View("Index"); > }>
>app.config(['$stateProvider', function ($stateProvider) { > $stateProvider.state('home', { > url: '/', > controller: 'max4salesController', > template: '' > }).state('edit', { > url: '/edit/:id', > controller: 'max4salesCrudController', > templateUrl: '/CapacityControl/max4sales/editForm' > }).state('new', { > url: '/new', > controller: 'max4salesCrudController', > templateUrl: '/CapacityControl/max4sales/editForm' > }).state('department', { > url: '/new/:departmentId', > controller: 'max4salesCrudController', > templateUrl: '/CapacityControl/max4sales/editForm' > }).state('category', { > url: '/new/:categoryId', > controller: 'max4salesCrudController', > templateUrl: '/CapacityControl/max4sales/editForm' > }).state('item', { > url: '/new/:itemId', > controller: 'max4salesCrudController', > templateUrl: '/CapacityControl/max4sales/editForm' > }).state('subCategory', { > url: '/new/:subCategoryId', > controller: 'max4salesCrudController', > templateUrl: '/CapacityControl/max4sales/editForm' > }); > }]);>