Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • glenatron 37 posts 132 karma points
    Dec 27, 2013 @ 18:15
    glenatron
    0

    How do routes work in 6.1.6?

    I have been reading the "How To Create Custom Controllers" article and I am still getting stuck on how to route a request to my controller.

    The document says:

    How the mapping works

    Document Type name = controller name

    Template name = action name

    but if no action matches or is not specified then the 'Index' action will be executed. In the near future we will allow setting a custom default controller to execute for all requests instead of the standard UmbracoController. Currently you'd have to create a controller for every document type to have a custom controller execute for all requests.

    So if my DocumentType is:

    • Name: Story
    • Alias: Story

    My Template is:

    • Name: News Story
    • Alias: Story

    And the News Story elements are all children of the /News list page, what do I have to do to run requests through a custom controller?

    If I allow it to generate the link automatically it comes out with ~/News/Headline-1 as the link and when I click on that it comes out with the content of my Story.cshtml view. However, it is crashing because it can't do something with the Model and I think this is because the model isn't being set up correctly because it isn't running through my StoryController class.

    I have tried:

    • StoryController with an Index method.
    • NewsStoryController with an Index method.
    • NewsPageController ( which handles the /News path ) with a Story method.
    • NewsPageController with a completely custom route - this actually routed through the method correctly, but put the request outside the Umbraco Pipeline so then my RenderModel-derived model didn't work.

    None of these work, or at least if I run in a debugger, none of the controller actions have a breakpoint that is hit at any point during the request.

    I don't really care what path I use, but I really need to be able to pick up these requests. Can anyone either offer any guidance on how to get it working or any suggestions on how to find out how Umbraco is routing the requests so I can figure out where to put these controllers? As it stands this is just unbelievably frustrating.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Dec 31, 2013 @ 12:39
    Jeavon Leopold
    0

    I'm not quite sure which bit you are missing but if you add a controller with the below code, and set a break point on the return, it will break when rendering a node of type "Story"

    using System.Web.Mvc;
    using Umbraco.Web.Models;
    using Umbraco.Web.Mvc;
    
    namespace MyUmbraoV7TestSite.Controllers
    {
        public class StoryController : RenderMvcController
        {
            public override ActionResult Index(RenderModel model)
            {
                //Do some stuff here, then return the base method
                return base.Index(model);
            }
    
        }
    }
    
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 02, 2014 @ 12:12
    Jeroen Breuer
    0

    If you want to experiment with Route Hijacking have a look at the Hybrid Framework. It has some nice examples.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft