I have Blog Repository and it contains blog posts list. I am accessing all Blog Posts by using this code
var contentType = ApplicationContext.Services.ContentTypeService.GetContentType("BlogPost");
var blogPostList = ApplicationContext.Services.ContentService.GetContentOfContentType(contentType.Id);
Now I am accessing custom data type properties by using
foreach (var blog in blogPostList)
{
foreach ( var property in blog.Properties)
{
}
}
Now I can access properties and get its value but for few properties I get json String and that is no use for me as I would need to create models to properly parse json string into proper json.
Is there any way to use GetPropertyValue in this situation or some other way to get properly formatted Json.
Are you using this code to display your blogpost on your website ?
If yes, this code will cause you performance problems real quickly, because ApplicationContext.Services.ContentService and ApplicationContext.Services.ContentTypeService hit the database and are not cached. It will also show deleted and unpublished content.
Get properties of a Blog Post
I have Blog Repository and it contains blog posts list. I am accessing all Blog Posts by using this code
Now I am accessing custom data type properties by using
Now I can access properties and get its value but for few properties I get json String and that is no use for me as I would need to create models to properly parse json string into proper json.
Is there any way to use GetPropertyValue in this situation or some other way to get properly formatted Json.
Hi Shahid,
Are you using this code to display your blogpost on your website ?
If yes, this code will cause you performance problems real quickly, because ApplicationContext.Services.ContentService and ApplicationContext.Services.ContentTypeService hit the database and are not cached. It will also show deleted and unpublished content.
If it's for display purposes you need to use the IPublishedContent interface (see https://our.umbraco.org/documentation/Reference/Querying/IPublishedContent/)
Dave
is working on a reply...