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
Is there any way to get a hierarchical list of what is
inside a Model?
I am looking for in razor is something equivalent with <xsl:copy-of select="." /> or xmldump project in xslt
I've done it before by creating a JSON string out of it, with a little creativity you can mold it into anything you want:
I achieved this by writing a quick razor helper that dumps all the properties out as a table. You can do this by creating a .cshtml file in App_Code folder. I called mine DiploHelpers.cshtml Inside it create a function like this:
@helper DumpProperties(umbraco.MacroEngines.DynamicNode node)
var items = node.PropertiesAsList;
<table width="100%" border="1" cellpadding="4" style="background-color:#eee;font-size:smaller">
@foreach (var item in items)
Then you can call this from your Razor file like so:
Of course, you can pass in any Node (not just the current Model and including Media nodes) to the helper.
Thank you for reply. I guess your code doesn’t cover the hierarchy between the Model’s children and grandchildren.
Well, you wouldn't always want to iterate over all descendent nodes, as that could mean iterating over a lot of nodes. But it would be easy enough to make the code recursive, if that is what you wanted.
What if you do not have an App_code folder? Does it matter where the helper lives?
You'd probably need to create an HtmlHelper method if you wanted it to be compiled as part of your solution.
Or I guess you could also use an HTML Partial class and pass in your model to it.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted