When rendering out a document type in Razor using DTGE.
Model.Content.Id always == 0.
I'm trying to render out something that require unique html IDs - eg. a set of accordions - for JavaScript to use as hooks.
Currently if I have two sets of accordions rendered out by the DTGE, the ID's in both sets are the same.
Does each instance of a document type in each grid panel get a unique ID (or anything unique that I can reuse)? As far as I can tell, their IDs are all 0, and things like the URL etc are blank.
Due to the nested nature of the DTGE data object (IPublishedContent) it is not a fully fledged "content node", as in it doesn't belong in the content tree, nor is it queryable from the content cache, (e.g. you can't do Umbraco.GetTypedContent(x) to return it).
You'll need to find an alternative way to setting a unique ID in your partial-view/markup.
Possible ideas are...
set an "ID" field in the DTGE doctype?
add a counter to your loop, then you'll have the current index/position of the item?
use an MD5 hash of the item's name? (e.g. Umbraco.CreateMd5Hash(Model.Content.Name)) but this requires the Name to be unique!
I thought that may be the case. But was worth asking before I moved on.
I have gone with a combination of DateTime.Now.Ticks (To identify the accordion set) and then a counter inside the foreach loop (to identify the accordion panel)
Get ID or Unique Identifier for instance of document type in razor
I'm sorry the title is awfully worded.
When rendering out a document type in Razor using DTGE. Model.Content.Id always == 0. I'm trying to render out something that require unique html IDs - eg. a set of accordions - for JavaScript to use as hooks. Currently if I have two sets of accordions rendered out by the DTGE, the ID's in both sets are the same.
Does each instance of a document type in each grid panel get a unique ID (or anything unique that I can reuse)? As far as I can tell, their IDs are all 0, and things like the URL etc are blank.
Hi David,
Due to the nested nature of the DTGE data object (
IPublishedContent
) it is not a fully fledged "content node", as in it doesn't belong in the content tree, nor is it queryable from the content cache, (e.g. you can't doUmbraco.GetTypedContent(x)
to return it).You'll need to find an alternative way to setting a unique ID in your partial-view/markup.
Possible ideas are...
Umbraco.CreateMd5Hash(Model.Content.Name)
) but this requires the Name to be unique!I hope this helps?
Cheers
- Lee
Thanks Lee.
I thought that may be the case. But was worth asking before I moved on.
I have gone with a combination of DateTime.Now.Ticks (To identify the accordion set) and then a counter inside the foreach loop (to identify the accordion panel)
is working on a reply...