Page types, menu, and URLs

Sylvain C. asked on August 1, 2019 01:16

Hello,

Working on my MVC project, I am really struggling building my URLs and making sure that it is consistent with my page type.
Following the MVC training, I started creating Doctor page type, office page type, etc.. Then, I was displaying my pages based on the doctor page type using my DoctorController and its associated views (DoctorIndex and DoctorDetail).
When I was showing my list of doctor, my URL was /Doctor/ -> Pointing to my Index action in DoctorController.
When I was showing one doctor, my URL was Doctor/Detail?name=xxx pointing to the Detail action in my DoctorController.

All of these look pretty simple even if I had to create the repositories, DTOs, controller and views for each one.

Then I start looking at the DancingGoat MVC site and saw that for every menu items, there was a distinct page type associated. Again the same logic was kept: A menu item corresponds to a page type which corresponds to a controller.

Then I started developing my own web site which will contain around 200 pages compiled in 20 menu sections. I started creating page types and rapidly found out that most of my page type for static content were the same:
A title section and a rich text editor section.

So I decided to move forward with a generic page type named “Content” which would fit 80% of my pages. The URL pattern is /{%DocumentCulture%}/Content/Detail/{%NodeAlias%} which points to my ContentController.

Then I start building my menu with main sections such as this one:

About us
|_  Doctors    
|_ Employment    
|_ Offices    
|_...

The About us is of “Content” page type for example and it original URL is /Content/Detail/About/
The Doctors is of “Doctor” page type for example and it original URL is /Doctor/
The Employment is of “Content” page type for example and it original URL is /Content/Detail/Employment/
The Offices is of “Office” page type for example and it original URL is /Office/

It was fine for some time but then I found out that from a SEO point of view, navigation, for the breadcrumb or in order to highlight to menu section (About us in this example) with some CSS, it was really messy as none of the sub menu items were related to each other using their URLs.

So I started playing with the RouteConfig in order to have all the URLs starting by the menu section: /About/ pointing to /Content/Detail/About/
/About/Doctors/ pointing to /Doctor/
/About/Employment/ pointing to /Content/Detail/Employment/
/About/Offices/ pointing to /Office/

I am now in a situation where I have to update my messy RouteConfing to point to the correct controller and action for every menu items and I have hundreds…
Moreover, what happen if my editor want to add a new page in the tree and I am not here? The page won’t be accessible as she won’t be able to update the RouteConfig.
What about the search results which keep their original URLs? The breadcrumb and the highlighting of the menu section when I click on a menu item is also not working.
Same thing when you add a link to another page. Again it is its original URL which is shown.

I used many other CMS and I never had to question myself of this aspect. It seems that with the portal engine model, it was easier as the tree reflected the menu directly which impacted the navigation, search tool, links etc... I have the feeling that I am doing something wrong but I don’t know how to make it work properly. I don’t want to create multiple identical page types for the only purpose of matching the URL. Also how am I supposed to deal with pages of different page types under the same menu section?

I thought I had found the solution with the latest Service pack and the alternative URLs but it won’t work for the search result or links to a page. The original URL will always be kept. Also switching from one culture to another with this code from the MVC training for an alternative URL will always switch to the original URL (/en-US/about/employment/ will be changed to /es-es/content/employment/):

@foreach (var culture in Model.Cultures)
                                    {
                                        var currentRouteValues = new RouteValueDictionary(
                                            Url.RequestContext.RouteData.Values
                                            )
                                        { ["culture"] = culture.CultureCode };
                                    <li>
                                        @*@ViewContext.RouteData.Values["action"]*@
                                        <a href="@Url.Action(
                                                        ViewContext.RouteData.Values["action"]?.ToString(),
                                                        ViewContext.RouteData.Values["controller"]?.ToString(),
                                                        currentRouteValues)">
                                            @culture.CultureShortName
                                        </a>
                                    </li>
                                    }

Sorry for this long question but I have been working on my site for weeks now and feel pretty uncomfortable with what I am doing.
Your experience on such a trivial issue would be very welcome.

Thank you for reading me

Sylvain

   Please, sign in to be able to submit a new answer.