Copied to clipboard

Flag this post as spam?

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


  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Mar 22, 2011 @ 16:55
    Biagio Paruolo
    0

    v4.7: Razor macro not executed, but display its code

    I wrote this macro into Razor script cshtml file:

    var Node = @Model.NodeById(1059);
    var Home = Node.AncestorOrSelf();
    Home.siteversion;
    @Model.AncestorOrSelf().siteversion;


    and insert macro into template, but rendering display me Razor script code and not its result.

    Why?

  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Mar 22, 2011 @ 18:17
    Biagio Paruolo
    0

    sorry but rendering display -> but display

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Mar 22, 2011 @ 18:24
    Sebastiaan Janssen
    0

    Is your .cshtml file linked in the macro as a script file? (click the image to enlarge it).

  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Mar 22, 2011 @ 18:26
    Biagio Paruolo
    0

    Yes..there is.

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Mar 22, 2011 @ 18:28
    Sebastiaan Janssen
    0

    Oh right, this is your only code?

    In that case you need to put it in a codeblock:

    @{
      var Node = @Model.NodeById(1059);
      var Home = Node.AncestorOrSelf();
      @Home.siteversion;
      @Model.AncestorOrSelf().siteversion;
    }
  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Mar 22, 2011 @ 18:47
    Biagio Paruolo
    0

    Which are cases that we should use codeblock?

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Mar 22, 2011 @ 20:12
    Sebastiaan Janssen
    0

    You use it when you have multiple lines of code, here is a good Razor introduction by Scott Guthrie.

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Mar 23, 2011 @ 09:25
    Sebastiaan Janssen
    0

    Don't forget to mark an answer as the correct solution so the next one with the same question can find it easily :-)

Please Sign in or register to post replies

Write your reply to:

Draft