Routing issues with multiple views in a module

Topics: General, Writing modules
Apr 18, 2012 at 2:13 PM

I am fairly new to MVC so bear with me here..  I created a module following the orchard HelloWorld documentation and named it ABC.Admin.  I created the HomeController.cs, a view - ABCAdmin.cshtml - and the Routes.cs that routes ABCAdmin to ABC.Admin (since that is the name of my project/area).  This works fine.  

However when I add another controller - Controllers/AdminController.cs - and a corresponding view in a different folder - Views/Admin/ManageInstructors.cshtml - and the appropriate route, and try to navigate to http://localhost:30320/OrchardLocal/ABCAdmin/ManageInstructors I get page not found.  

I'm sure I'm missing something obvious here .. any ideas?

 

 

AdminController:

namespace ABC.Admin.Controllers
{
    [Themed]
    public class AdminController : Controller
    {
        public ActionResult ManageCourses()
        {
            return View();
        }
        
        public ActionResult ManageInstructors()
        {
            return View();
        }

        public ActionResult ManageLocations()
        {
            return View("ManageLocations");
        }

        public ActionResult ManageRosters()
        {
            return View("ManageRosters");
        }

    }
}

 

Routes.cs:

    public IEnumerable<RouteDescriptor> GetRoutes()
        {
            return new[] {
                new RouteDescriptor {
                    Priority = 6,
                    Route = new Route(
                        "ABCAdmin", 
                        new RouteValueDictionary {
                            {"area", "ABC.Admin"},
                            {"controller", "Home"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "ABC.Admin"}
                        },
                        new MvcRouteHandler())
                },
                new RouteDescriptor {
                    Priority = 5,
                    Route = new Route(
                        "ABCAdmin/Admin",
                        new RouteValueDictionary{
                            {"area", "ABC.Admin"},
                            {"controller", "Admin"},
                            {"action", "ManageInstructors"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary{
                            {"area", "ABC.Admin"}
                        },
                        new MvcRouteHandler())
                }
            };
        }

Coordinator
Apr 18, 2012 at 7:08 PM

I think the view should be in Views/Admin, and by convention it won't be accessible unless you're logged in.

Apr 18, 2012 at 8:53 PM

It is is that folder already.  And I am logged in, although this is a separate module - not part of the built in Admin functionality in Orchard.  I tried changing the name to something other than "Admin" in case there is some convention rule in Orchard around using that word in my module but it didn't seem to do the trick.  

Apr 18, 2012 at 10:47 PM

ahhhh...nevermind I think I have this worked out.  It seems that using Admin in my module is the same as the Orchard Admin pages in that it requires the user to be logged in - as you mentioned - which can come in handy.  In this case I want to provide pages available to authenticated users but do not want them to have access to all the normal site management tools.  So I'll just create a different controller and views for users that need to be authenticated in this way.