I currently have 2 controllers, MemberController and Admincontroller, and is working fine if I use it like the below (different actions) :
http://localhost/member/delete/ME222
http://localhost/admin/view/AD321
I have my route config which looks like this :
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home",
action = "Index", id = UrlParameter.Optional }
);
But now I have created a shared action (Detail) for both Member and Admin, which I put in my SharedController, and want to access it like so :
http://localhost/member/detail/ME222
http://localhost/admin/detail/AD321
Ofcourse when I hit the above url’s, the action does not exist in the Admin- and MemberController.
How do I route the the above to go to the SharedController’s action if the current current action in the controller (member or admin) does not exist? (not just the Detail action, but for all actions that doesn’t exist)
Thanks
David
If you have common actions for both controllers you may simply create
UserControllerwhich will be base class forMemberandAdmincontrollers. Then you may put all common actions insideUserControllerand it should work.If you want to override something (or for example put mark actions with different attributes for each role) you may make action virtual and then override it in child class.