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:
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.
How to list what is in a Razor Model
Hi,
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 territory.
Thank you
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:
http://cultiv.nl/blog/2011/7/25/razor-vs-base-to-output-json-in-umbraco/
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:
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.
Hi Dan,
Thank you for reply. I guess your code doesn’t cover the hierarchy between the Model’s children and grandchildren.
Thanks,
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.
Dan, 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.See https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/views/creating-custom-html-helpers-cs
https://www.foreach.be/blog/create-a-custom-html-helper-in-asp-net-mvc-using-razor
Or I guess you could also use an HTML Partial class and pass in your model to it.
is working on a reply...