It's taken me a while to figure out the correct syntax too... mostly because I find working with the older (DynamicNode) Razor quite painful (I generally dislike dynamics anyway).
With the Razor model-binding (for uComponents) enabled, you should be able to do this:
Replace the "Model.com" with "Model.[whatever your property alias is]" ... this will give you a .NET type of "List<string[]>" (e.g. a list of string arrays), (but no one would ever know that because it's "dynamic" (meh!) ... then you can loop through each array (for your rows), then through each sub-array (for your cells).
Thanks for the help. I tried this in the meantime but got stuck again one extra Column here.
Anyways yours work like a charm !!
var items = XDocument.Parse(new DynamicNode(Model.Id).GetProperty("comp").Value.ToString()); var rows = items.Descendants("values"); var columns = items.Descendants("value");
<table>
<tbody>
@if(rows.Count() > 0){
foreach(var r in rows){
<tr>
@foreach(var cell in rows)
{
<td></td>
}
</tr>
}
} </tbody>
</table>
TextStringArray uComponents
Hi,
Am knocking my head with this dataType and i see no documentation on it either.
Right now i created a new dataTypewith property TextStringArray using 3 rows and each having 2 columns.
So my Html needs to render something like
Now when i get the values from the Model this is how it renders
This is my actual code
Everything gets all mess up and cant figure out how to make a new row depending on the entry row from the backend
Any suggestion on this PLEASE ?
I ususally do a
var xml=XDocument.Load(s.GetProperty("companyFactsheet").Value.ToString()) and use xpath to iterate the xml.
var descendants = xml.Descendants("values") should get you each row and
foreach(var descendent in descendants) { var values = descendant.Descendants("value"); } should get you each col for a specific row.
Cheers,
/Dirk
Am gettiing error Error loading MacroEngine script.
Pretty odd, i'm sure it *must* work using my approach. Bit clueless why your version wouldn't.
/Dirk
Am i missing something here ?
Here is the full code
Hi Fuji, quick question... Which version of Umbraco and uComponents? (it will help me answer faster)
Thanks, Lee
Hi Lee, working with v 4.11.8 and uComponents 5.5.0
Instead of using
var xml=XDocument.Load(s.GetProperty("com").Value.ToString());
i used
var items = XDocument.Parse(new DynamicNode(Model.Id).GetProperty("com").Value.ToString());
Thanks Fuji.
In your Web.config do you have an appSettings key called "ucomponents:RazorModelBinding"? If so what's the value of it?
I'm hoping that you'll be able to use the model-binding, as it's much easier than messing around with XML in Razor.
Cheers, Lee
It is set to true .
Hi Fuji,
It's taken me a while to figure out the correct syntax too... mostly because I find working with the older (DynamicNode) Razor quite painful (I generally dislike dynamics anyway).
With the Razor model-binding (for uComponents) enabled, you should be able to do this:
Replace the "Model.com" with "Model.[whatever your property alias is]" ... this will give you a .NET type of "List<string[]>" (e.g. a list of string arrays), (but no one would ever know that because it's "dynamic" (meh!) ... then you can loop through each array (for your rows), then through each sub-array (for your cells).
Hope this works for you.
Cheers, Lee.
Hi Lee,
Thanks for the help. I tried this in the meantime but got stuck again one extra Column here.
Anyways yours work like a charm !!
Thanks
Lee what will be the appropriate way of getting the value of a column in a specific row ?
I will have to make a total sum of some of the entries in those cell.
You would need to use a
for
loop to have the index of the current position.e.g.
Cheers, Lee.
Not exactly what am trying to achieve here.
What i need to do is to get the value of each cell so at the end i will be able to make a total sum.
My Html would end up something like
Do you mean something like this?
Silly question where did you get rows here ?
The reason i need to get the cell values seperately is because i will need those values to make some calculations in percentage to make a chart.
Sorry - I missed that out of my code snippet.
The
rows
would be assigned fromModel.com
(replacing with whatever your property alias is).using row[1] will only return the first character from the value here
May be i would be best counting the rows since i only have 1 column.
You're so close... it doesn't need the inner-
foreach
loop. Try this:This is actually the first thing i tried!!
Not working though! :)
I am having a similar problem - the razor example does not return anything except the table tags.
Perhaps razor binding is broken for my install?
what should the Web.Config line for appsettings be? everytime I try to enable in the activate section of dev tab, it says its disabled -
so ive manually added in appsettings :
(umbraco 6.1.4, uComponents_5.5.0, IIS 7.0, .NET VersionASP.Net 4.0/4.5)
thanks in advance for help.
Marc
is working on a reply...