Copied to clipboard

Flag this post as spam?

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


  • John Bergman 460 posts 1066 karma points
    Jan 25, 2017 @ 05:53
    John Bergman
    0

    MVC Routing or SurfaceRouting Question (newbie)

    Anyone have any idea how to automatically add a route for a document type that has no template to a surface controller?

    I'd settle for an attribute or code; I just cannot seem to quite understand how this is wired together.

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Jan 25, 2017 @ 07:17
    Dave Woestenborghs
    1

    Hi John,

    Surface controllers are auto-routed, so you can not assign a route to it. I even think if you try to that you will break your site.

    See the docs of surface controllers to know more about them : https://our.umbraco.org/documentation/Reference/Routing/surface-controllers

    What you are looking for is "Route Hijacking". See the docs for route hijacking : https://our.umbraco.org/documentation/Reference/Routing/custom-controllers

    Let's assume that your doctype has alias of "noTemplate"

    What you would do then is create a controller that inherits from RenderMvcController and is named as following : doctypealias + Controller. In this case that would be NoTemplateController

    public class NoTemplateController : Umbraco.Web.Mvc.RenderMvcController
    {
        public override ActionResult Index(RenderModel model)
        {
            //Do some stuff here, then return the base method
            return this.View("NoTemplateViewPath", model: model);
        }
    
    }
    

    In the index method you will set the correct view that you want to render.

    Dave

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies