Copied to clipboard

Flag this post as spam?

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


  • Meni 247 posts 483 karma points
    May 01, 2016 @ 18:51
    Meni
    0

    Converting old Razor scripts to MVC Partial views macro files

    Hey, I've searched but haven't find - any good tutorial how to convert my old Razor scripts to MVC Partial views macro files? (U 7.x)

    In the "old" Razor files I'm using a lot @using umbraco.NodeFactory;

    dynamic NAME_node = Library.NodeById(1xxx);

    etc. Not sure whether this the reason for the errors? Looking for a good guide to the new world of MVC - how to convert the old Razor script to MVC. Using 7.4.2 If I choose the "old" Razor - things work. Once I change to the new partial view (which is the same code - just did copy-paste from the directory on the server, to the new "MVC Partial views macro files" on the CMS - it's suddenly doesn't work.

    Please advise. Thanks :)

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    May 02, 2016 @ 08:47
    Dan Diplo
    0

    Have you checked out the documentation? Specifically have a look at:

    https://our.umbraco.org/documentation/Reference/Templating/Mvc/

    https://our.umbraco.org/documentation/Reference/Querying/

    A quick rule of thumb is that you replace Library with the Umbraco Helper. So where you had:

    dynamic NAME_node = Library.NodeById(1xxx);
    

    you would replace with:

    var node = Umbraco.Content(1xxx);
    

    or for strongly-typed (recommended) you would use:

    var node = Umbraco.TypedContent(1xxx);
    

    The latter returns details as IPublishedContent which is the equivalent of Node.

Please Sign in or register to post replies

Write your reply to:

Draft