Copied to clipboard

Flag this post as spam?

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


  • Arun Gahlot 5 posts 25 karma points
    Oct 25, 2012 @ 10:35
    Arun Gahlot
    0

    custom property not found after assignment

     

    Hello,

    I am new to Umbraco/Razor (and to .net development also please bear with me for a moment), the following code is a razor macro.

    @using System.Diagnostics
    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    
    @{
        String thisis = "";
        DynamicNode video = null;
        DynamicNodeList listOfVideos = null;
        if (@Model.NodeTypeAlias == "VideoFAQ")
        {
            thisis = "one particular video";
            video = @Model;
            listOfVideos = @Model.Ancestors("VideoFAQPage").Items[0].Children.Where("NodeTypeAlias == \"VideoFAQ\"");
        }
        else if (@Model.NodeTypeAlias == "VideoFAQPage")
        {
            thisis = "A Page containing lot of videos.";
            video = @Model.VideoFAQ.Items[0];
            listOfVideos = @Model.VideoFAQ;
        }
    }

    When I try to do this 

    @video.HtmlMarkup

    HtmlMarkup is a property defined on the Document Type , the same works if I do it the @Model.HtmlMarkup way.

    There comes an error, My guess is that it is because the way I am constructing this.

    can someon please tell me what is going on.... and if there is a better way to do it.

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 25, 2012 @ 11:20
    Fuji Kusaka
    0

    Hi Arum,

    What error message are you getting?

    Can you try addding

    @inherits umbraco.MacroEngines.DynamicNodeContext

    to your code

    //fuji

  • Arun Gahlot 5 posts 25 karma points
    Oct 29, 2012 @ 06:11
    Arun Gahlot
    0

    I am still getting the error.

    Error loading MacroEngine script (file: ~/macroscripts/videofaq/anothertest.cshtml)
    

    The code is now.

    @using System.Diagnostics
    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext @{
        String thisis = "";
        DynamicNode video = null;
        DynamicNodeList listOfVideos = null;
        if (@Model.NodeTypeAlias == "VideoFAQ")
        {
            thisis = "one particular video";
            video = @Model;
            listOfVideos = @Model.Ancestors("VideoFAQPage").Items[0].Children.Where("NodeTypeAlias == \"VideoFAQ\"");
        }
        else if (@Model.NodeTypeAlias == "VideoFAQPage")
        {
            thisis = "A Page containing lot of videos.";
            video = @Model.VideoFAQ.Items[0];
            listOfVideos = @Model.VideoFAQ;
        }
        @video.HtmlMarkup
    }

    I don't know if it matters a lot, but I am loading the macro (as i saw in the Cultiv Razor examples...by using the filelocation attribute of the Umbraco:macro tag)

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 29, 2012 @ 12:16
    Fuji Kusaka
    0

    Hi Arun,

    Can you try removing the @ symbol within the if statment so as 

    if(Model.NodeTypeAlias = "VideoFAQ"){
    thisis = "one particular video"; 
    }

    @(Html.Raw(@thisis));
    @Model.HtmlMarkup
  • Arun Gahlot 5 posts 25 karma points
    Oct 30, 2012 @ 05:53
    Arun Gahlot
    0

    Hi Fuji,

    I tried that and it is not working.

    I think it has to do something about the way these assigments are taking place, I am very new to .net development, but as far as I know (and I hope I am right)... while creating @Model umbraco does something to the DynamicNode (like add some methods and properties to the runtime object) and when In the code I am trying to reassign these to other variables (which are basically DN and DNL), these magic things are not coming to me, it seems that they are being assigned by a copy and not by reference. Some syntatic sugar goes missing...

    The reason I say so is because the following seems to be working fine.

    @Html.Raw(@video.GetPropertyValue("htmlMarkup")); 

    And the following Won't work

    @Html.Raw(@video.HtmlMarkup) 

    I am also getting a Red Squiggly line  with the following error message in visual studio

    umbraco.MacroEngines.DynamicNode does not contain a definition for HtmlMarkup and no extension method 'HtmlMarkup' accepting a first arguement of type 'umbraco.MacroEngines.DynamicNode' could be found (are you missing a using directive or an assembly reference) 

    Cheers,
    Arun

     

Please Sign in or register to post replies

Write your reply to:

Draft