Copied to clipboard

Flag this post as spam?

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


  • Chris C 43 posts 184 karma points
    May 08, 2014 @ 05:44
    Chris C
    0

    umbraco 7 and razor dynamic woes

    Hi.  I did a test run upgrade to version 7.  So I'm not sure if my terminology is correct, but now the razor macros throw exceptions.  They fail when accessing custom properties, like - page.CustomProperty.  

    So here is some sample code that will no longer work.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using System.Linq;
    @{
        var subpages = CurrentPage.Descendants("umbPage").OrderBy("Name");
        foreach (var page in subpages) {
            string x = page.CustomProperty;   // this line craps out
        } 
     }

    On version 6, this worked.  Is there a different way to do this on 7?  Thanks.  

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 08, 2014 @ 11:57
    Jeavon Leopold
    100

    This looks generally ok, perhaps try changing your variable to being implicit instead of explicit, e.g.

    var x = page.CustomProperty;
    

    Also do you know what the error is?

  • Chris C 43 posts 184 karma points
    May 08, 2014 @ 17:21
    Chris C
    0

    Thanks Jeavon.  I put the "string x" just as an example.  The exception happens on page.CustomProperty, and the debugger says that the property does not exist.

    I also tried page.Properties["CustomProperty"], but that didn't work either.  Did something change with dynamics in Umb7?

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 08, 2014 @ 20:52
    Jeavon Leopold
    0

    How about doing some checks to see if that changes things?

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var subpages = CurrentPage.Descendants("umbPage").OrderBy("Name");
        foreach (var page in subpages)
        {
            if (page.HasProperty("CustomProperty") && page.HasValue("CustomProperty"))
            {
                string x = page.CustomProperty; // this line craps out
            }
        }
    }
    
  • Chris C 43 posts 184 karma points
    May 09, 2014 @ 19:40
    Chris C
    0

    Hmmm, ok.  Your first suggestion worked.

    var x = page.CustomProperty;

    Then I could call x.ToString() or do whatever I needed.  

    So it seems like something has indeed changed with the datatypes when I upgraded to 7.  The custom properties used to come through as strings.  

    Thanks again.  

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 09, 2014 @ 20:03
    Jeavon Leopold
    0

    Lets see what it is then

    @x.GetType().ToString()
    
  • Chris C 43 posts 184 karma points
    May 12, 2014 @ 21:29
    Chris C
    0
    @x.GetType().ToString()

    Unfortunately I had to scrap plans to go to version 7 for the time being, because of this and other problems.  Will definitely try that when I get a chance though.  

Please Sign in or register to post replies

Write your reply to:

Draft