Copied to clipboard

Flag this post as spam?

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


  • James Jackson-South 489 posts 1747 karma points c-trib
    Mar 18, 2015 @ 16:32
    James Jackson-South
    1

    Using traditional MVC controller structure and routing in Umbraco

    In traditional MVC you can set up a controller as follows

    public class ProductsController {
    
        public ActionResult Index(){
    
            // general products stuff.
    
        }
    
        public ActionResult Product(int id){
    
            // product specific stuff.
    
        }
    }
    

    With this I can have the routes

    • /products
    • /products/product/1

    Great! I get to reuse a controller as nature intended. Yay MVC!

    With Umbraco, as far as I have ever been able to ascertain, to achieve those routes, you have to follow this pattern:

    public class ProductsController : RenderMvcController {
    
        public override ActionResult Index(){
    
            // general products stuff.
    
        }
    }
    
    public class ProductController : RenderMvcController {
    
        public ActionResult Product(int id){
    
            // product specific stuff.
    
        }
    }
    

    I hate having to create a new controller every time I want sub pages under a route.

    Question is... Have I missed something? Have I been slowly driving myself mad doing it incorrectly or is this simply how Umbraco works?

    I could do whacky things using IContentFinder or by defining additional routes using the new technique here but that feels and is hacky.

    If this is the way things are then why is it laid out that way?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 20, 2015 @ 10:51
    Dave Woestenborghs
    0

    Hi James,

    Maybe this article by warren can help you out : http://creativewebspecialist.co.uk/2013/12/03/using-umbraco-pipeline-for-member-profile-urls/

    Dave

  • James Jackson-South 489 posts 1747 karma points c-trib
    Mar 20, 2015 @ 15:26
    James Jackson-South
    0

    Hi Dave,

    No absolutely not I'm afraid.

    That's using the IContentFinder plus a whole lot of hackery which has been superseeded by using the combination of MapUmbracoRoute and UmbracoVirtualNodeRouteHandler which is still a hack in my opinion.

    It's pretty screwy the way it works just now. Doctypes in the back office should have some sort of rootprovider option which would allow routing to follow the traditional format.

    Cheers

    James

Please Sign in or register to post replies

Write your reply to:

Draft