Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    May 26, 2017 @ 14:43
    Dibs
    0

    Hi Umbarco Team Trying to create a custom route to make use of a custom controller and Action method.

    I have created the following class :

    public class StartMeUp : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            RouteTable.Routes.MapRoute(
                "test",
                "{controller}/{action}",
                new
                {
                    controller = "MyController",
                    action = "MyAction"
                });
        }
    } 
    

    But i still get no route in route table ? Am i going about this the wrong way ?

    thanks Dibs

  • Gary Cheetham 20 posts 144 karma points
    May 27, 2017 @ 14:28
    Gary Cheetham
    0

    Hi, try using RouteTable.Routes.MapUmbracoRoute

    Or, depending on what you're trying to do you might not even need to register custom routes at all and a SurfaceController or RenderMvcController in your assembly is all you need.

    Take a look at the documentation here: https://our.umbraco.org/Documentation/Reference/Routing/

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    May 29, 2017 @ 08:40
    David Brendel
    0

    Hi Dibs,

    is the controller a umbraco type controller? So SurfaceController or RenderMvcController?

    Think if you are using a SurfaceController you also have to use an additional interface. Don't remember the name right now.

    If you are using normal mvc stuff it could be that you have to tell umbraco to not try to map the url to content by adding it to the umbracoReservedUrls app setting.

    Regards David

  • Dibs 202 posts 991 karma points
    May 29, 2017 @ 12:38
    Dibs
    0

    Hi David/Gary

    I'm trying to follow MVC protocol to implement a custom controller, which has both custom model and partial view. My end goal is to make use of the partial view in multiple Umbraco template views.

    The controller has an action method to return a list of published content, i would like to make use of this action method in more then one template via:

    @{Html.Render action("Action","Controller")}
    

    This works when i make the controller inherit from SurfaceController:

    public class MyController : SurfaceController
        {
            // GET: 
            public ActionResult MyAction()
            {
                var rl = new MyModel(CurrentPage);
                rl.rootList = Umbraco.TypedContentAtRoot().First().Children;
                return PartialView("MyModel", rl);
            }
        }
    

    When i inherit from RenderMvcController

     public class MyController : RenderMvcController
        {
            // GET: 
            public ActionResult MyAction(RenderModel model)
            {
                var rl = new MyModel(model.Content);
                rl.rootList = Umbraco.TypedContentAtRoot().First().Children;
                return PartialView("MyView", rl);
            }
        }
    

    I get the no route error BSOD message

    Dibs

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    May 29, 2017 @ 13:29
    Frans de Jong
    100

    RenderMvcController needs a documenttype and a contentnode. You have to name the controller [documenttypealias]controller and than it will work.

Please Sign in or register to post replies

Write your reply to:

Draft