Copied to clipboard

Flag this post as spam?

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


  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Dec 07, 2013 @ 08:37
    Jesper Ordrup
    0

    Razor - How to check if content is in the recycle bin?

     foreach (var childPage in Model.Children.Where("Visible"))
                {
                    var customerAccessId = childPage.customerAccess;
       if (customerAccessId == member.Id)
                    {
        <div>
            <a href="@childPage.Url">
                @childPage.Name</a>
        </div>
                    }

     

    This code breaks if one of the childpages is in the recycle bin. How to proper check if stuff is deleted?

    Best
    Jesper

     

                }

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 09, 2013 @ 12:17
    Jeroen Breuer
    0

    If it's in the recycle bin it's unpublished so it shouldn't even be accessible in Razor. Strange that you get this exception.

    What version of Umbraco are you using? This is the old and legacy Razor macro code. You should use new Razor code: http://our.umbraco.org/documentation/reference/Templating/Mvc/

    Jeroen

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Dec 10, 2013 @ 08:22
    Jesper Ordrup
    0

    It's Umbraco 6.16.

    It was probably published at the time it was deleted. But yes - very strange.

    Thanks for the link. I've just looked it over. I've only been using Razor for a shorter period (4-5 month) so I've got some to learn. Your link points to MVC templating and related stuff. I seen the page before but there's no hint that its relevant to me wanting do code razor macros in a masterpage controlled solution. 

    So I'm confused :-)

    /Jesper

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 10, 2013 @ 09:22
    Jeroen Breuer
    100

    That documentation is if you run in MVC mode so all your templates are already Razor views. 

    However you can also create a macro for a masterpage controlled solution which is using these new techniques. It's called a partial view macro. There isn't a lot of documentation about it yet, but in the developer section there is a "Partial View Macro Files" tree. That will also create a Razor Macro, but with all the new (and faster!) techniques like IPublishedContent. It's beter to create a macro as a "Partial View Macro Files" instead of the old legacy (and slow) "Scripting Files" macro.

    Jeroen

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Dec 10, 2013 @ 10:17
    Jesper Ordrup
    0

    Thank you Jeroen. Very valuable information. I'm gonna try using partials instead. 

    Thanks again,
    Jesper 

Please Sign in or register to post replies

Write your reply to:

Draft