Copied to clipboard

Flag this post as spam?

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


  • David Turnbull 2 posts 22 karma points
    Feb 21, 2014 @ 10:13
    David Turnbull
    0

    How to sucessfully link to another cms page in Umbraco

    I am growing increasingly frustrated with Umbraco. I've been working on an Umbraco project for a little while now and I have been unable to figure out how to solve my problem (one of many).

    Scenario - I have a content managed page and on this page users can search for things (these things come from an entirely different database to Umbraco). This is fine, I've created a child action which loads the form for search and created the controller method which returns the results. However, each result I need to link to another content managed page (the same content managed page for each result) that takes an ID so I can inject some dynamic data into the content managed page.

    Great, I've got a method for handling this request in my surface controller and I can create an Html.ActionLink for each result that when clicked hits my controller action with the id parameter.

    Problem - When each link is clicked the url that gets hit is

    http://localhost:5645/umbraco/surface/{controllername}/{actionname}/?id={id}
    

    However this request is outside the Umbraco context, so when I try to return any page with the following controller code, I get the following error:

        [ActionName("ShowDetials")]
        public ActionResult GetProperty(int propertyId)
        {
            return View("~/Views/TestView.cshtml");
        }
    

    Cannot render a macro when UmbracoContext.PageId is null.

    So my initial thoughts were to have a separate controller which inherits from Umbraco.Web.Mvc.RenderMvcController and try to handle the request in there, but then this raises other issues like being unable to use @Html.ActionLink to link to a RenderMvcController, I also don't want to have two controllers to handle content from the same section.

    The other issues I have is passing custom models to the view.

    If anyone can help me, I would be eternally grateful.

  • David Turnbull 2 posts 22 karma points
    Feb 21, 2014 @ 14:38
    David Turnbull
    0

    For any developer having this same issue the only way I have been able to solve it is by having two controllers. A surface controller to handle the initial rendering of the search form and page and to display the results of the search, then a separate rendermvccontroller to handle clicking on an individual result and displaying a 'details' page.

    However, this in my opinion isn't great and I would still greatly appreciate it if anyone has another solution.

  • 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