Fluent API to capture custom Field

Posted by Community Admin on 05-Aug-2018 15:32

Fluent API to capture custom Field

All Replies

Posted by Community Admin on 25-Apr-2011 00:00

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);
 
             
        
    

I know DataItem is not null because it sets the appropriate navigate url...but when I try and get the custom field it throws out a Object not set error.

Any ideas?

Posted by Community Admin on 26-Apr-2011 00:00

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

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Posted by Community Admin on 26-Apr-2011 00:00

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

Posted by Community Admin on 29-Apr-2011 00:00

Hello Jerami,

I am closing the thread, since the issue looks like resolved.

Greetings,
Ivan Dimitrov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

This thread is closed