I have property name of a field and I need to get the value. For example I have "Device Name" and the alias is deviceName. So how do I get the value of this field if I have only "Device Name":
Hi Kevin,
I don't need this, the name can be "Device Name" but the property alias can be devName I don't think it will work like this, and I need it to work always
The cached published content only knows the aliases, so I think you'd have to use the ContentTypeService. You'd probably want to cache the results if you need to do this a lot.
Something like this should work:
var contentTypeId = publishedContent.ContentType.Id;
var contentType = ApplicationContext.Services.ContentTypeService.GetById(contentTypeId);
var property = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Name == propertyName);
var propertyAlias = property.Alias;
Get property value of a field
Hi,
I have property name of a field and I need to get the value. For example I have "Device Name" and the alias is deviceName. So how do I get the value of this field if I have only "Device Name":
Thanks
Hi Sonja,
you can't guarantee it will always work because the user can choose to manually change the alias of a property, but :
the
.ToSafeAlias()
string extension would do this for you.e.g
requires
Using Umbraco.Core
Hi Kevin, I don't need this, the name can be "Device Name" but the property alias can be devName I don't think it will work like this, and I need it to work always
The cached published content only knows the aliases, so I think you'd have to use the ContentTypeService. You'd probably want to cache the results if you need to do this a lot.
Something like this should work:
Hi Steve,
can I do this in a partial view? Also I need the value, not the alias.
is working on a reply...