I have a usercontrol with an update panel which displays filtered product information. Some of the values are created in Umbraco using the Textstring array. Below is a the generated xml for the Textstring Array:
As I'm displaying other properties on the page I've created a node object and have been using the GetProperty method. This is fine for the product name etc... But I not usre if I can use the same approach with the Textstring Array.
Code extract:
var node = new Node(Convert.ToInt16(ddl.SelectedValue));//Selected node ID via drop down menu on web site page //display other property valuse //.. string aerValues = node.GetProperty("previousAERRates").Value; //Iterate over value pairs and display on page
Would be grateful if someone could advise on how I can get the XML so that I can display each set of values in the update panel.
Which version of uComponents and which type of Razor are you using? (e.g. macroScript or MVC/partial)
For the Razor macroScripts we have a custom model-binder that should be used automatically, this should give you the value as an List<string[]> object type. You can loop over that accordingly.
With MVC Razor, we have a PropertyEditorValueConverter that will do the same thing, but it's only available in uComponents v6+ (supports Umbraco 6.1+)
Since you also have 2 values in your Textstring Array you could use something like this:
private IEnumerable<ProductProperty> GetProperties(IPublishedContent content)
{
var xml = content.GetPropertyValue<XElement>("properties");
if (xml == null)
{
return Enumerable.Empty<ProductProperty>();
}
var properties =
(
from x in xml.Descendants("values")
let elements = x.Elements()
select new ProductProperty()
{
Text = elements.ElementAt(0).Value,
Value = elements.ElementAt(1).Value
}
);
return properties;
}
Sorry, I'm using Umbraco 4.11.10 and uComponents 5.5.0. So have a usecontrol in a webform and then using the code behind to display the various property values. With this version could you advise on the references that I need to add to the usercontrol project.
Jeroen - thanks for your solution, will give this a try if I can't access the custom model-binder that lee mentioned.
Once you get back the value from node.GetProperty("previousAERRates").Value you should have an XML string. You could then pass it to a function that will return you something more usable.
var values = new List<string[]>();
if (!string.IsNullOrEmpty(yourValueFromPreviousAERRates))
{
var xml = new XmlDocument();
xml.LoadXml(yourValueFromPreviousAERRates);
foreach (XmlNode node in xml.SelectNodes("/TextstringArray/values"))
{
var value = new List<string>();
foreach (XmlNode child in node.SelectNodes("value"))
{
value.Add(child.InnerText);
}
values.Add(value.ToArray());
}
}
From there, you can do as Jeroen mentions, loop through the list and output the first and second values.
Using Node API with Textstring Array
Hi,
I have a usercontrol with an update panel which displays filtered product information. Some of the values are created in Umbraco using the Textstring array. Below is a the generated xml for the Textstring Array:
As I'm displaying other properties on the page I've created a node object and have been using the GetProperty method. This is fine for the product name etc... But I not usre if I can use the same approach with the Textstring Array.
Code extract:
Would be grateful if someone could advise on how I can get the XML so that I can display each set of values in the update panel.
Best Wishes.
Eddie
Hi Eddie,
Which version of uComponents and which type of Razor are you using? (e.g. macroScript or MVC/partial)
For the Razor macroScripts we have a custom model-binder that should be used automatically, this should give you the value as an
List<string[]>
object type. You can loop over that accordingly.With MVC Razor, we have a PropertyEditorValueConverter that will do the same thing, but it's only available in uComponents v6+ (supports Umbraco 6.1+)
Cheers, Lee.
Since you also have 2 values in your Textstring Array you could use something like this:
Jeroen
Hi Lee,
Sorry, I'm using Umbraco 4.11.10 and uComponents 5.5.0. So have a usecontrol in a webform and then using the code behind to display the various property values. With this version could you advise on the references that I need to add to the usercontrol project.
Jeroen - thanks for your solution, will give this a try if I can't access the custom model-binder that lee mentioned.
Thanks,
Eddie
Hi Eddie,
No problem-o, usercontrols are fine.
Once you get back the value from
node.GetProperty("previousAERRates").Value
you should have an XML string. You could then pass it to a function that will return you something more usable.e.g. code snippet taken from the Razor model-binder
From there, you can do as Jeroen mentions, loop through the list and output the first and second values.
Cheers, Lee.
is working on a reply...