By Name I'm guessing you want to get the value of the property with the alias of "bandName"?
Assuming the property editor you have used is a simple textbox then the code you already have will be able to get the value out. A better way to do it might be with this line of code:
var bandName = item.GetPropertyValue<string>("bandName");
Remember to check the alias is correct and your query is pulling back results in the first place.
If you have a more complex property editor then you might need to use a PropertyValueConverter to pull the object out and then select the appropriate value from there.
Hi Paul,
Thanks for the answer but for the value I have no problem I try to retrieve the name of the textbox field corresponding to my alias
for example for my alias BandNumber are name is Band Number
for example for my Tel alias are name is Tel Number
I hope you understand my explanation
Cédric
I think I can see what you are trying to do now but I'm unsure why you would need to take this approach. The property name is not really part of the content, for that reason, it's not included in the IPublishedContent model and is not easily accessible without expensive queries against the ContentTypeService.
I would recommend you hardcode the values, you are hardcoding the alias so why not the name?
If you really do need to get the name for a property on a content type then as I said the ContentTypeService is where you will find that information.
Something like this might work depending on your content type make up.
Thank you, I need this function because the user backoffice has the opportunity to rename the name of the textbox and it avoids me to change it in the code.
After I hardcoder the fields because I do not see how to create my model view with my controller relative to a type of document.
thanks for the help
Retrieve Name of Custom Property
Hi all, Please how to retrieve the Name of a Custom property ? For example :
Hi Cedric,
By Name I'm guessing you want to get the value of the property with the alias of "bandName"?
Assuming the property editor you have used is a simple textbox then the code you already have will be able to get the value out. A better way to do it might be with this line of code:
Remember to check the alias is correct and your query is pulling back results in the first place.
If you have a more complex property editor then you might need to use a PropertyValueConverter to pull the object out and then select the appropriate value from there.
Paul
Hi Paul, Thanks for the answer but for the value I have no problem I try to retrieve the name of the textbox field corresponding to my alias for example for my alias BandNumber are name is Band Number for example for my Tel alias are name is Tel Number I hope you understand my explanation Cédric
Hi Cedric,
I think I can see what you are trying to do now but I'm unsure why you would need to take this approach. The property name is not really part of the content, for that reason, it's not included in the IPublishedContent model and is not easily accessible without expensive queries against the ContentTypeService.
I would recommend you hardcode the values, you are hardcoding the alias so why not the name?
If you really do need to get the name for a property on a content type then as I said the ContentTypeService is where you will find that information.
Something like this might work depending on your content type make up.
Hope this helps,
Paul
Thank you, I need this function because the user backoffice has the opportunity to rename the name of the textbox and it avoids me to change it in the code. After I hardcoder the fields because I do not see how to create my model view with my controller relative to a type of document. thanks for the help
is working on a reply...