Copied to clipboard

Flag this post as spam?

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


  • Tom Bruce 122 posts 506 karma points
    Sep 22, 2017 @ 14:46
    Tom Bruce
    0

    Hi folks, looking for some help here;

    I have a hyperlink that a user can click on; the hyperlink will render a page.

    I would like to pass a parameter to the template of that page.

    Basically I’m trying to pass a parameter from the hyperlink to the template,

    which will then pass the parameter to action within the controller.

    Hyperlink to page.

    <a href="@Umbraco.NiceUrl(1193)">Go</a>
    

    Template of page

    @{ Html.RenderAction("Action", "Controller");}
    
  • Craig Mayers 164 posts 508 karma points
    Sep 22, 2017 @ 15:18
    Craig Mayers
    0

    Hi Tom,

    I tend to use @Url.Action helper.

    See the following article:

    http://techfunda.com/howto/251/get-url-of-action-method

    Hopefully this will point you in the right direction.

    Craig

  • Tom Bruce 122 posts 506 karma points
    Sep 22, 2017 @ 15:32
    Tom Bruce
    0

    Thanks Craig, but it doesn't show you how to pass a parameter with the Umbraco syntax

    <a href="@Umbraco.NiceUrl(1193)">Go</a>
    
  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Sep 22, 2017 @ 15:38
    Dennis Aaen
    0

    Hi Tom,

    Have you tried to have a look at this documentation

    https://our.umbraco.org/documentation/Reference/Templating/Mvc/child-actions#RenderingaChildAction

    Hope this helps,

    /Dennis

  • Tom Bruce 122 posts 506 karma points
    Sep 22, 2017 @ 15:44
    Tom Bruce
    0

    OK this what I have so far, still no parameter being passed to the render action

    Hyperlink

       <a href="@(Umbraco.NiceUrl(1295))?EditStatus=1">Edit Details</a>
    

    Template

      @{ Html.RenderAction("Action", "Controller", new { EditStatus = "EditStatus" });}
    
  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Sep 22, 2017 @ 16:34
    Dennis Aaen
    0

    Hi Tom,

    Is it´s something like this that you are trying to do

    <a href="@Umbraco.NiceUrl(1193)[email protected]">Go</a>
    

    Then the final url will be http://www.yourdomain.com/page?p=1040 where 1040 is the id of the page that you are viewing in the browser.

    Hope this helps,

    /Dennis

  • Craig Mayers 164 posts 508 karma points
    Sep 22, 2017 @ 16:42
    Craig Mayers
    0

    Hi Tom,

    You can use the Request object to access the querystring values in your Action.

    E.g. Request.QueryString["NameOfYourQueryString"]

    You can then use those values as you see fit in your Action logic.

    Thanks

    Craig

  • Tom Bruce 122 posts 506 karma points
    Sep 22, 2017 @ 16:52
    Tom Bruce
    0

    How do I pass the parameter EditStatus from the href to the render action,

      @Html.Action("RenderEligibilityChecks", "Applicant", EditStatus })
    
  • Craig Mayers 164 posts 508 karma points
    Sep 22, 2017 @ 17:03
    Craig Mayers
    0

    Try

    @Html.ActionLink("Click ME!", "ActionNameHere", new { EditStatus = 1})
    

    Depending on the Location of your Action you might have to use one of the many overloads for @Html.ActionLink and pass in the ControllerName.

    E.g. http://some-site.com/Controllerame/ActionName?EditStatus=1

    Craig

  • Tom Bruce 122 posts 506 karma points
    Sep 22, 2017 @ 17:10
    Tom Bruce
    0

    Thanks Craig, but I'm not trying to pass to the Controller, I'm trying to pass the parameter to the RenderAction

  • Ben Palmer 176 posts 842 karma points c-trib
    Nov 14, 2017 @ 13:00
    Ben Palmer
    0

    Hi Tom,

    You'd be passing it through to the method (i.e. the action) in that controller.

    So if you put together answers from both Dennis and Craig, you'd get something like:

    <a href="@Umbraco.NiceUrl(1193)?editStatus=1">Go</a>
    

    And:

    @{ Html.RenderAction("Action", "Controller", new { editStatus = Request.QueryString["editStatus"] });}
    

    Action will be in a controller and would have editStatus as a parameter. Does that achieve what you're trying to do?

  • Sahar 10 posts 79 karma points
    Nov 14, 2017 @ 12:34
    Sahar
    0

    I want to achieve the same thing i.e. passing the parameter from anchor to the template (or you can say Umbraco page that calls the template).

    Plz update if anyone has solved this.

    thanks

  • Ben Palmer 176 posts 842 karma points c-trib
    Nov 15, 2017 @ 07:18
    Ben Palmer
    0

    Hi Sahar,

    Can you post the method/controller that you're calling in your template?

    My above answer should get you half way there, if you then need to pass it through to the view, you can do so in the method in the controller. Be easier to see that controller first however to give you proper advice.

Please Sign in or register to post replies

Write your reply to:

Draft