Copied to clipboard

Flag this post as spam?

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


  • MK 429 posts 906 karma points
    Mar 11, 2012 @ 10:57
    MK
    0

    Get the property values using razor

    Hi there,

    Im trying to get the values out of the node using razor but all I get is the following:

    <data><item id="1"><TestName propertyid="1">Available colours</TestName><TestValue propertyid="2">yellow, green, purple, orange</TestValue><TestLinkedMediaItem propertyid="3">1093</TestLinkedMediaItem><TestLinkedContentItem propertyid="4">1070</TestLinkedContentItem><TestValidFrom propertyid="5">2012-03-13 15:46</TestValidFrom></item><item id="3"><Name propertyid="1">package measurments</Name><Value propertyid="2">50x80x40</Value><LinkedMediaItem propertyid="3">1097</LinkedMediaItem><LinkedContentItem propertyid="4">1068</LinkedContentItem><ValidFrom propertyid="5">2012-03-31 06:13</ValidFrom></item><item id="2"><Name propertyid="1">package weight</Name><Value propertyid="2">50k</Value><LinkedMediaItem propertyid="3">1092</LinkedMediaItem><LinkedContentItem propertyid="4">1064</LinkedContentItem><ValidFrom propertyid="5">2020-03-11 17:40</ValidFrom></item></data>

     

    Any idea?

    Many thanks

     

     

  • MK 429 posts 906 karma points
    Mar 11, 2012 @ 14:32
    MK
    0


     

    Here you go:

    @using System.Xml;
    
    @{
        var currentNode = umbraco.presentation.nodeFactory.Node.GetCurrent();
       var strValue =  @currentNode.GetProperty("productSpecification").Value;
    
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(strValue);
        XmlNode element = xmlDoc.SelectSingleNode("/data");
        
        <ul>
            @foreach(XmlNode  item in @element){
                <li>
                 @item.InnerText;
                    <br />
                </li>
                         
            }
        </ul>
                         
      }
    
    
    
  • MK 429 posts 906 karma points
    Mar 12, 2012 @ 08:15
    MK
    0

    Even Better:

    @using System.Xml;
    
    @{
        var currentNode = umbraco.presentation.nodeFactory.Node.GetCurrent();
       var strValue =  @currentNode.GetProperty("productSpecification").Value;
    
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(strValue);
        XmlNode element = xmlDoc.SelectSingleNode("/data");
        
        <ul>
            @foreach(XmlNode item in @element.ChildNodes)
            {
    
       
    
                 <li>
                  @Html.Raw(item["Name"]!=null ? item["Name"].InnerText : ""): 
                  @Html.Raw(item["Value"] != null ? item["Value"].InnerText : "")
                </li>
                         
               
              }
        </ul>
                         
            }
  • Tony Kiernan 278 posts 341 karma points
    Apr 04, 2012 @ 13:55
    Tony Kiernan
    1

    I had an embedded content datatype called faq, with two text fields faqQuestion and faqAnswer.  This works:

    @{
        var faq = Model.faq;

                @foreach(dynamic item in faq)
                {
                        <p>
                            @item.faqQuestion.InnerText
                        </p>

                        <p>
                            @item.faqAnswer.InnerText
                        </p>           
    } }
  • Ilan Galini 1 post 21 karma points
    Apr 23, 2012 @ 09:39
    Ilan Galini
    0

    Tony,

    Which @using directives did you use there?

    I can't seem to get your solution to work.

  • Tony Kiernan 278 posts 341 karma points
    Apr 23, 2012 @ 10:43
    Tony Kiernan
    0

    None. What I posted there is (give or take a div or two) the razor file.

     

Please Sign in or register to post replies

Write your reply to:

Draft