I've been trying for a while now to figure out how to get the data out of the uComponents TextstringArray data type. It's stored as XML. Here's the XML from the cmsContentXml table:
As a side question, does anyone know why there is an extra node called "TextstringArray" inside my defined property? The other uComponent types (e.g. Multiple Textstring) don't store their data like that.
Back to my ACTUAL question. I'm having trouble getting to that data using Razor. I'm trying to get the data into javascript variables, but I'd be having the same problems if I were putting it into HTML. Here are some of the things I've tried (inside a script tag):
var css = []; @foreach (var x in Model.sermonCSS){ @:css.push(@x.value[0].InnerText); }
var css = []; @foreach (var x in Model.sermonCSS){ @:css.push(@x.Value[0].InnerText); }
var css = []; @foreach (var x in Model.sermonCSS.TextstringArray){ @:css.push("@x.Value[0].InnerText"); }
Etc. etc. I think you get the point. I've tried just about every combination and can't get anything out of it. Whenver I do console.log(css), it's just an empty array ( [ ] ). Has anyone worked with this data type and know how to get at the data?
This is using Umbraco 4.7.1 on Windows 7 with .NET 4.0.
I ended up loading the raw XML (stored in the property - in your case this would be Model.sermonCSS) and loading it into an XDocument and then parsing that into a DTO class. Something like this:
private static int GetElementAsInt(IEnumerable<XElement> elements, int position)
{
int number = 0;
var elem = elements.Skip(position).Take(1).FirstOrDefault();
if (elem != null)
{
int.TryParse(Regex.Replace(elem.Value, "[^0-9]", String.Empty), out number);
}
return number;
}
Obviously the class KeywordData would need to have the properties appropriate for your data. Not straightforward, but once you've done it you can work nicely with a strongly-typed list of values.
Working with TextstringArray in Razor
Hey everyone,
I've been trying for a while now to figure out how to get the data out of the uComponents TextstringArray data type. It's stored as XML. Here's the XML from the cmsContentXml table:
As a side question, does anyone know why there is an extra node called "TextstringArray" inside my defined property? The other uComponent types (e.g. Multiple Textstring) don't store their data like that.
Back to my ACTUAL question. I'm having trouble getting to that data using Razor. I'm trying to get the data into javascript variables, but I'd be having the same problems if I were putting it into HTML. Here are some of the things I've tried (inside a script tag):
Etc. etc. I think you get the point. I've tried just about every combination and can't get anything out of it. Whenver I do console.log(css), it's just an empty array ( [ ] ). Has anyone worked with this data type and know how to get at the data?
This is using Umbraco 4.7.1 on Windows 7 with .NET 4.0.
I ended up loading the raw XML (stored in the property - in your case this would be Model.sermonCSS) and loading it into an XDocument and then parsing that into a DTO class. Something like this:
is working on a reply...