Copied to clipboard

Flag this post as spam?

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


  • suzyb 464 posts 877 karma points
    Sep 02, 2013 @ 17:39
    suzyb
    0

    CurrentPage / Model.Content in partial view

    In my form partial view I'm trying to get a sibling of the current page to add some navigation in.  But I cannot seem to work out how to get the current page.

    My partial inherits from a custom model

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<CheckoutModel>

    so Model.Content / CurrentPage is unavailable.  I could use @Umbraco.TypedContent but as I cannot work out how to get the ID of the current page I cannot use that.

    Can anyone help?

  • Charles Afford 1163 posts 1709 karma points
    Sep 02, 2013 @ 18:49
    Charles Afford
    0

    When you say you cannot get it to work?  What is the problem?  Charlie :)

  • suzyb 464 posts 877 karma points
    Sep 02, 2013 @ 20:05
    suzyb
    0

    In my partial view if I try and get the next sibling using this code it gives a The name 'CurrentPage' does not exist in the current context error.

    var test = CurrentPage.Next();

    Trying it this way gives,  'Racing.CheckoutModel' does not contain a definition for 'Content' and no extension method 'Content' accepting a first argument of type 'Racing.CheckoutModel' could be found (are you missing a using directive or an assembly reference?)

    var test2 = Model.Content.Next();

     

  • Charles Afford 1163 posts 1709 karma points
    Sep 02, 2013 @ 23:13
    Charles Afford
    0

    Umbraco.Web.Mvc.UmbracoViewPage

    Thats because of this statement and i am not sure how to fix it.

    Try using Umbraco.Web.Mvc.UmbracoViewPage

    and dont use any of the model properties, just to assert this is the case. Charlie :)

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Sep 03, 2013 @ 12:16
    Jeroen Breuer
    1

    You could let your custom model inherit from RenderModel (which Umbraco uses everywhere): http://our.umbraco.org/forum/templating/templates-and-document-types/38311-Using-RenderMvcController?p=2#comment153025

    So you have your own model with it's own properties, but Model.Content will also work.

    Jeroen

  • Charles Afford 1163 posts 1709 karma points
    Sep 03, 2013 @ 12:23
    Charles Afford
    0

    Jeroen, this sounds like a great solution. Can you just call Model...... ect ect from your own model?

    If the context is null will this throw? Charlie :)

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Sep 03, 2013 @ 12:32
    Jeroen Breuer
    101

    You can just do Model.YourOwnProperty, but also Model.Content.Children to get the children of the current node.

    Jeroen

  • suzyb 464 posts 877 karma points
    Sep 03, 2013 @ 13:12
    suzyb
    0

    Setting my CheckoutModel to inherit from RenderModel allows me to get the sibling using Model.Content however I get this exception when posting my form.

    No parameterless constructor defined for this object.

    When I give CheckoutModel a parameterless constructor it moans that RenderModel doesn't have a constructor that doesn't allow it.

    I don't see how to pass the currentpage to my model during the post however.

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Sep 03, 2013 @ 13:19
  • suzyb 464 posts 877 karma points
    Sep 03, 2013 @ 13:45
    suzyb
    1

    Note to self, scroll through threads in case there is anything else pertinent ;)

    Thanks Jeroen

  • suzyb 464 posts 877 karma points
    Sep 03, 2013 @ 13:54
    suzyb
    0

    Doh just marked the wong post as 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