Copied to clipboard

Flag this post as spam?

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


  • Chuck 71 posts 69 karma points
    Mar 01, 2011 @ 21:41
    Chuck
    0

    bodyText from node with ID

    I'm really new to working with Razor, in fact this is my first attempt at using it. What I want to do is create a macro in which I can display bodyText from a node that I know the ID of. Here is what I have, I am creating a razor script in the scripts file.

    var contentNode = new DynamicNode(1511);
    @contentNode.bodyText

    Though this looks correct to me, when I try to save the script I get an error with the following details.

    c:\Windows\Temp\aqpapjch.0.cs(22,7) : error CS0103: The name 'contentNode' does not exist in the current context

    What am I doing wrong?

  • Jonas Eriksson 930 posts 1825 karma points
    Mar 01, 2011 @ 21:45
    Jonas Eriksson
    1

    Hi, the razor parser needs to have var declarations within @{} , you can simply choose to enclose the whole script within it like so:

    @{
    var contentNode = new DynamicNode(1511);
    @contentNode.bodyText
    }
Please Sign in or register to post replies

Write your reply to:

Draft