Copied to clipboard

Flag this post as spam?

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


  • Simon 692 posts 1068 karma points
    Dec 17, 2014 @ 09:46
    Simon
    0

    Querying Relations in Razor View

    Hi,

    I am new to Umbraco, and appreciate any help. I am using nuPickers for relating a school class with student document types. I have achived that where a class has a number of students.

    But now, in the class template, I would like to know to query relations so that in the school class template I will be able to display all students of that class.

    I am using Umbraco 7+

    Appreciate any help.

    thanks

    Simon

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 17, 2014 @ 09:57
    Dave Woestenborghs
    0

    Have a look at the GetRelations method of uQuery : http://our.umbraco.org/documentation/Reference/Querying/uQuery/Relations

    Dave

  • Simon 692 posts 1068 karma points
    Dec 17, 2014 @ 09:59
    Simon
    0

    Instead of hard coded IDs, how can I get the page ID?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 17, 2014 @ 10:03
    Dave Woestenborghs
    0

    @Model.Content.Id or @CurrentPage.Id

  • Simon 692 posts 1068 karma points
    Dec 17, 2014 @ 10:07
    Simon
    0

    It is throwing an error that The name 'CurrentPage' does not exist in the current context

  • Simon 692 posts 1068 karma points
    Dec 17, 2014 @ 10:20
    Simon
    0

    Ok Dave, I was not inherting from @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

  • Simon 692 posts 1068 karma points
    Dec 17, 2014 @ 10:27
    Simon
    0

    Hi Dave,

    What is the namespace/reference for Document, because I want to get Document By Id and use such properties?

     

    thank you.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 17, 2014 @ 12:04
    Dave Woestenborghs
    0

    You can do @Umbraco.TypedContent(idofyournode).

    Dave

  • Simon 692 posts 1068 karma points
    Dec 17, 2014 @ 12:13
    Simon
    0

    What is the difference betwen @Umbraco.TypedContent(1112) and @Umbraco.Content(1112)?

     

    Thanks

    simon

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 17, 2014 @ 12:23
    Dave Woestenborghs
    0

    TypedContent returns a strongly typed object of type IPublishedContent. 

    Content returns a dynamic object.

    The same goes for @Model.Content and @CurrentPage

  • Simon 692 posts 1068 karma points
    Dec 17, 2014 @ 12:39
    Simon
    0

    And what is the difference between strongly typed object and dynamic object  in Umbraco?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 17, 2014 @ 12:51
    Dave Woestenborghs
    0

    With the strongly typed you have intellisense in visual studio.

    I will try to explain the difference for getting a property of your content called "visual".

    With the strongly typed object you will do :

    @Model.Content.GetPropertyValue("visual")

    With dynamic you will do

    @CurrentPage.Visual.

    The last one will try to call the first one under the hood and will fail if it can be found.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft