Fluent API to capture custom Field
In my blog post section I've created a custom field called preview image. I see its stored in the database and has the appropriate values. Now im trying to render that field into my markup. When I make a call through the Fluent API to retrieve a list of Blog Posts Im not sure how I can capture that custom field. I've tried dataItem.GetValue<string>("preview_image") but that throws an error.
Here is how Im capturing all the data:
var articles = App.WorkWith().BlogPosts().Get().Where(ab => ab.Parent.Title == ARTICLESBLOGNAME && ab.Status == ContentLifecycleStatus.Live).OrderByDescending(ab=>ab.PublicationDate);
I then bind this to a ListView and it displays all the data like Summary, Title and such as you would expect...I think set up a OnItemDataBound event:
protected void ArticlesItemDataBound(object sender, ListViewItemEventArgs e)
if(e.Item.ItemType == ListViewItemType.DataItem)
var dataItem = (BlogPost)((ListViewDataItem) e.Item).DataItem;
var link = (HyperLink)e.Item.FindControl("NavHyperLink");
link.NavigateUrl = string.Format("/articles0", dataItem.Urls.FirstOrDefault().Url);
var previewImage = (Image)e.Item.FindControl("PreviewImage");
var imageUrl = dataItem.GetValue<
string
>("preview_image");
if (string.IsNullOrEmpty(imageUrl)) return;
previewImage.ImageUrl = string.Format("/img/featured/0", imageUrl);
Hello Jerami,
Try calling DoesFieldExist method - Extension method that determines if the dynamic field exists on the type. From what you described it looks like your custom field does not exist for the content item.
Regards,
Ivan Dimitrov
the Telerik team
Yeah I looked at the database and was attempting to capture the field by its field_name rather then what I specified in the administrative section.
Thanks
Hello Jerami,
I am closing the thread, since the issue looks like resolved.
Greetings,
Ivan Dimitrov
the Telerik team