I have a view that both edits and creates “usergroups”. And I have a “usergroup-detailsview” (Admin/Usergroup/43) where I have 2 links:
Html.RouteLink("Edit", "UsergroupEdit",
new { usergroupID = Model.Usergroup.UsergroupID })
Html.RouteLink("Create", "UsergroupCreate")
In my global.asax I got:
routes.MapRoute("UsergroupEdit", "Admin/Usergroup/Edit/{usergroupID}",
new { controller = "UsergroupsAdmin", action = "Edit" } );
routes.MapRoute("UsergroupCreate", "Admin/Usergroup/Edit",
new { controller = "UsergroupsAdmin", action = "Edit" } );
The first one where the int is passed in renders:
Admin/Usergroup/Edit/87
But the second one renders like:
Admin?Length=24
How can I fix this route?
/M
To remain sane 😉 and to keep things clear use two routes:
Also from code I see you have a controller name UsergroupsAdmin..If you have somewhere there also a Usergroups controller, you better get rid of UsergroupsAdmin and just decorate “admin” actions in Usergroups controller with [Authorize action filter.
For Authorize you can implement your own Role provider so you can check your requirements there. It will keep things very clean and maintainable.
If you decide to keep Edit route, just make sure to have only one like this:
and check in controller action where usergroupID=0, render create view.