Copied to clipboard

Flag this post as spam?

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

  • Tim C 155 posts 512 karma points
    Jul 01, 2020 @ 22:50
    Tim C

    How to get node by id in app_code cshtml

    Not sure how to get a node by id and return its property values in a generic razor file in app_code.

    Any suggestions gratefully received.

  • Mario 130 posts 809 karma points c-trib
    Jul 01, 2020 @ 23:00

    If you want to create a Razor helper to be reused by your views, I would recommend you to get the node in your views (or controllers in a view model) and pass it to you helper function, instead getting the node in the helper itself.

  • D K M J 74 posts 229 karma points
    Jul 02, 2020 @ 18:46
    D K M J



    var content = Umbraco.Content(1063)

    Or use content services.

  • Tim C 155 posts 512 karma points
    Jul 02, 2020 @ 19:10
    Tim C
    @using Umbraco
    @using Umbraco.Core.Services
    @using Umbraco.Web
    @using Umbraco.Web.Composing
    @using Umbraco.Core.Models.PublishedContent
    @using System.Web
    public static IPublishedContent test(int Id){
        var ttt = Umbraco.Content(Id);
        return null; /* just testing to see if it compiles */

    Returns error:

    Compiler Error Message: CS0234: The type or namespace name 'Content' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
    Source Error:
    Line 16: 
    Line 17: public static IPublishedContent test(int Id){
    Line 18:    var ttt = Umbraco.Content(Id);
    Line 19:    return null;
    Line 20: }

    Do I need to include a different 'using' namespace? (ythis is cshtml in the app_code folder)


Please Sign in or register to post replies

Write your reply to: