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 65 posts 316 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 Im 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 137 posts 451 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 65 posts 316 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 4246 posts 17241 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 65 posts 316 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 4246 posts 17241 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)?p=@Model.Content.Id">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 137 posts 451 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 65 posts 316 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 137 posts 451 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 65 posts 316 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 61 posts 236 karma points
    5 days ago
    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 2 posts 71 karma points
    5 days ago
    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 61 posts 236 karma points
    4 days ago
    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