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
Does anyone know how to get the Name (not alias) of a property in Razor?
If you are using a dynamic node you can just @MyDynamicNode.MyPropertyAlias and access it like that, or if you are using a regular Node, then you would do @MyNode.GetProperty("MyPropertyAlias")
It's something like that! Hope I've pointed you in the right direction at least! :)
Oops looks like I've misread your post!
It's just Name, e.g.
If you want to see all of them, you could try:
@foreach (var child in DynamicModel.Children)
<textarea rows="40" cols="40">
@foreach(PropertyDescriptor descriptor in TypeDescriptor.GetProperties(child.ContentType))
@Html.Raw(name + "=" + value +"\n") }
This forum really doesn't like you pasting code in
This doesn´t work when you need Name of Property
foreach (var item in list)
var proplist = item.Properties;
foreach (var prop in proplist)
prop.Name doesn´t work in this case, but name is written somewhere in database. Can i uncover this field to be able to display it?
Howdy Zedna -- Did you have any success in accessing a property's name? I'm having the same issue...
So weird that it's not included with the actual property...
Just wanted to followup on this as I've finally got a solution in place, hopefully this helps someone who lands in the same boat as I have been the past few days.
So my issue has been that the Properties list present on nodes returned from Umbraco.Content(whatever).Children contained property values and their respective aliases but did not contain the actual name/label of the property.
I found that a lookup must be performed on the node's content type, the result here was an object that contained both the alias and name!
Here's the relevant code that's worked for me. Note: I opted to create a dictionary to output my property names where needed.
int ContentTypeId; // ex: [YourUmbracoNode].ContentType.Id
var cts = ApplicationContext.Current.Services.ContentTypeService;
var ct = cts.GetContentType(ContentTypeId);
Dictionary<string, string> propMap = new Dictionary<string, string>();
foreach (var propertyType in ct.PropertyTypes)
Hopefully this helps someone out there.
Hobbled together from these other, related, threads:
Write your reply to:
Image will be uploaded when post is submitted