Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
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> }
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> }
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> } }
Tony,
Which @using directives did you use there?
I can't seem to get your solution to work.
None. What I posted there is (give or take a div or two) the razor file.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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
Here you go:
Even Better:
I had an embedded content datatype called faq, with two text fields faqQuestion and faqAnswer. This works:
Tony,
Which @using directives did you use there?
I can't seem to get your solution to work.
None. What I posted there is (give or take a div or two) the razor file.
is working on a reply...