Find the view according to the Url

Feb 13, 2011 at 2:01 AM

To take the url "http://localhost:30320/OrchardLocal/Admin/Users" as example.

I know it's Routes.cs who set the route rules, but there are so many modules and Routes.cs and I think it's stupid to go through all of them one by one, right? And I've tried search "Admin/User" or "Admin/{" in the whole resolution but found nothing.

In fact, it's a question have been torturing me for a long time.  Is there any CONVENIENT way to find the view, control and model through the Url directly?

Thanks very much in advance.

Feb 13, 2011 at 2:24 AM

I also have been trying to do the same thing to find out where I would be able to fix my container details view problem. I've come to the conclusion that the routing information we are looking for is only found in the database as a RoutePart record, but I have not been able to look in the database as I don't know how to query the SqlCe database. I should google that now I guess, but I thought I should be able to add it as a database connection in visual studio, but it crashed when trying to load it. Maybe it would be easy to create a page that would list all the routeparts in the database with their slugs and types.

Feb 13, 2011 at 3:08 AM

WebMatrix will allow you to easily view the tables (and data) in the SqlSe database.

Feb 13, 2011 at 3:30 AM

Are you sure, I use MS Sql 2005 and find the following data in table "Routable_RoutePartRecord":

11    11    Welcome to Orchard!    welcome-to-orchard    welcome-to-orchard
15    15    My Blog    my-blog    my-blog
18    18    New Blog Post    new-blog-post    new-blog-post
19    15    My Blog    my-blog  

It seems not concern about route rule?

And it's the first time that I hear that the route data is stored in database. Is it loaded in memory when application launches? See the following code:

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Blogs.Routing;
using Orchard.Mvc.Routes;

namespace Orchard.Blogs {
    public class Routes : IRouteProvider {
        private readonly IBlogSlugConstraint _blogSlugConstraint;

        public Routes(IBlogSlugConstraint blogSlugConstraint) {
            _blogSlugConstraint = blogSlugConstraint;
        }

        public void GetRoutes(ICollection<RouteDescriptor> routes) {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }

        public IEnumerable<RouteDescriptor> GetRoutes() {
            return new[] {
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Blogs/Create",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Orchard.Blogs"},
                                                                                      {"controller", "BlogAdmin"},
                                                                                      {"action", "Create"}
                                                                                  },
                                                         new RouteValueDictionary(),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Orchard.Blogs"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Blogs/{blogId}/Edit",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Orchard.Blogs"},
                                                                                      {"controller", "BlogAdmin"},
                                                                                      {"action", "Edit"}
                                                                                  },
                                                         new RouteValueDictionary (),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Orchard.Blogs"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                         // omit some here ......

}; } } }

Feb 13, 2011 at 4:55 AM

No, I'm not sure at all, but those slugs there in the database are turned into routes or at least looked up when a request comes in. Some others are created on the fly or at load time from the names of types and such, so /Admin/Users is probably showing an EditorTemplate for the User part.

Feb 14, 2011 at 2:01 PM

Is there anyone can help me? I think it's mandatory to know for us, and I don't know where is the source code for http://localhost:30320/OrchardLocal/Admin/Navigation now.

Developer
Feb 14, 2011 at 2:13 PM

Hi!

Orchard core features, such as Navigation, are placed in Orchard.Core project. So the code for http://localhost:30320/OrchardLocal/Admin/Navigation will be under Orchard.Core/Navigation. If you want the view which displays the items' table its under: /Views/Admin/Index.cshtml . Corresponding controller is AdminController in the /Controllers folder (as in ordinary ASP.NET MVC app).

Hope I was helpful:)

Cheers, Piotr

Feb 14, 2011 at 2:22 PM

pszmyd,

Thanks very much! It helps me a lot.

Mar 2, 2011 at 11:05 AM

I found it helpful to show the source code of the rendered admin page and to look at the html tag :

<html lang="en" class="static navigation"> 

The word after "static " represents the MVC area which inside Orchard seems to be the module ID ( = folder name) where dots are translated to hyphens).

Also there seems to be some (undocumented yet) magic which allows the url "~/NiceModuleAreaName/Controller/View/id" to be accessed by the following URL when the controller is named "Admin(Controller)": "~/Admin/NiceModuleAreaName/View/id" -- where View and id are optional as usual (when View is named "Index").

Mar 2, 2011 at 1:20 PM

It's interesting! Thanks