Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MVC
hi all,,,,
I have one doubt on asp.net mvc 3 routing..Iam doing a project in mvc3.In my application there is an admin side and also public user side..
I have a controller that is adminController to login the admin..In the adminController there is two action methods for login and home.So the url look like
www.mySite.com/admin/login
 
www.mySite.com/admin/home
 
I have created another folder Admin in the controller folder only for accessing administrators and created ManageMembersController in the Admin folder..and the url should look like

www.mySite.com/admin/ManageMembers/list
 
I have written the custom routing in the global asax file..
routes.MapRoute(
                           "Admin", // Route name
                           "Admin/{controller}/{action}/{data}", // URL with parameters

                           new
                           {
                               controller = "/Admin/ManageMembers",
                               action = "list",
                               data = UrlParameter.Optional
                           } // Parameter defaults
                       );
            routes.MapRoute(
               "admin_default", // Route name
               "admin/{action}/{id}", // URL with parameters
               new { controller = "admin", action = "login", id = UrlParameter.Optional } // Parameter defaults
           );
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Pub", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
 

 

 
My problem is that when iam trying to www.mySite.com/admin/login I got an error
'The resource cannot be found.'
but the other routing worked properly..
that is www.mySite.com/admin/ManageMembers/list it redirected to the ManageMembersController
 
My requirement is to redirect to Controller/adminController.cs when the url is www.mysite.com/admin/..
and it must redirect to Controller/Admin/ManageMembers.cs when the url is www.mySite.com/Admin/ManageMembers/..
I need your suggestions...
 

Thank you Devguys...
Posted 8-Feb-11 19:34pm
Comments
justinonday at 9-Feb-11 6:59am
   
good luck .
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To have two different controllers with the same name, you'll probably need to organize them into separate areas[^]. As far as I know, you'll then be able to specify the corresponding area for each controller in the routing with something like this:
 
routes.MapRoute(
     "Default",
     "{area}/{controller}/{action}/{id}",
     new { area = "YourArea", controller = "Admin", action = "List", id = UrlParameter.Optional }
);
 
etc...
 
I hope this is helpful.
Phil
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

how to run if you have multi subfolder?
Ex: Admin/Component/ComUser/User/
Admin/Component/ComMenu/Menu/
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 20 Apr 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid