Copied to clipboard

Flag this post as spam?

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


  • Newbraco 41 posts 164 karma points
    May 07, 2018 @ 11:10
    Newbraco
    0

    Extra parameters when using route hijacking

    I have implemented route hijacking by using @inherits UmbracoViewPage[MyModel] in the view and MyModel inherits from RenderModel, everything works fine.

    In my controller I have

    public override ActionResult Index(RenderModel rm)
    {
        var myModel = new MyModel(rm.Content, rm.CurrentCulture);
        ... 
       return CurrentTemplate(myModel);
    }
    

    My question is: How do I take another parameter in my Index-method?

    I have tested having another method like

       public ActionResult MyIndex(RenderModel rm, int customerId)
        {
            //same as above
        }
    

    (since I have seen such solutions on forums) , but I cant call it from my browser by instead of going to

    http://... /mycustomerpage/myindex?customerId=23

    Is this just a routing problem or how do I send extra parameters?

  • kows 81 posts 151 karma points c-trib
    May 07, 2018 @ 13:16
    kows
    100

    I'm guessing that "MyIndex" isn't a template defined on the related document type? Actions inside a RenderMvcController map to that specific document type's templates. Index is called for all templates.

    So I would rename "MyIndex" to your template's name. You don't have to mention this part in the url. Or provide more clarity about the related document type & available templates.

  • Newbraco 41 posts 164 karma points
    May 07, 2018 @ 14:04
    Newbraco
    0

    Holy kows! Thanks :D

    Renaming my Index2 to the name of the template helped. Thanks alot!

    I must admid I was kind of clueless about that RenderMvcController mapped to a specific template.

    In in this example I had 1 DT and 1 Page Template

  • Newbraco 41 posts 164 karma points
    May 07, 2018 @ 14:07
    Newbraco
    0

    ... with this (an old question from me here on this forum) I guess that you can have one controller for the document type and then a method for each page template. (I havent thought about what that actually means or if its smart to do so... but I guess you could)

  • kows 81 posts 151 karma points c-trib
    May 08, 2018 @ 05:11
    kows
    0

    Depends on what you need to implement. Most of the time we usually only have 1 template / document type so it doesn't really make a difference. Index can be used for shared logic across all templates, Template specific action is also logic specific for that template.

Please Sign in or register to post replies

Write your reply to:

Draft