+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to know what type for dynamic content?

How to know what type for dynamic content?

5 posts, 0 answered
  1. Ryan
    Ryan avatar
    16 posts
    Registered:
    22 Jan 2014
    01 Apr 2014
    Link to this post

    I have a custom content type I created in the backend. Now I am accessing that type in a widget. I have several fields all as short text, but they are not strings? They are Lstring? I added another field that is also short text but when I load the widget it says it is not Lstring?

    How can I know what to depend on here? Is there a list of what types are associated with which fields? How can short text sometimes be Lstring and sometimes not? I'm baffled by how some of this software works. After 2 days I've come across numerous of these head scratchers. Also, why even use a custom string type? What is wrong with C# string?

  2. Ryan
    Ryan avatar
    16 posts
    Registered:
    22 Jan 2014
    01 Apr 2014
    Link to this post

    Here is the code....all fields are just short text, but Title is saying that Lstring is incorrect type:

    var dynamicTestimonial = dynamicRepository.GetByID(id);
    var name = dynamicTestimonial.GetValue<Lstring>("Name");
    var title = dynamicTestimonial.GetValue<Lstring>("Title");
    var company = dynamicTestimonial.GetValue<Lstring>("Company");

  3. David C
    David C avatar
    33 posts
    Registered:
    02 Dec 2015
    01 Apr 2014
    Link to this post
    Hi Ryan,

    Have you tried setting your properties to string types instead of vars? Here's a working sample that I have in my dynamic content type model:

    public string Title { get; set; }

    public AnnouncementsModel(DynamicContent sfAnnouncementsItem)
    {
                this.Title = sfAnnouncementsItem.GetValue<Lstring>("Title");
    }

    Also, make sure you have the following using statement in your code:

    using Telerik.Sitefinity.Model;

    Regards,
    David C
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  4. Ryan
    Ryan avatar
    16 posts
    Registered:
    22 Jan 2014
    02 Apr 2014 in reply to David C
    Link to this post

    The implicit typing is not the issue. Is there a reference where I can see the types for each field? It's hard for a developer to assume a string field is going to be reflected as a custom string type Lstring. I'm afraid further widgets I'm building are going to have me banging my head against  a wall guessing what type it's going to want me to cast to.

  5. David C
    David C avatar
    33 posts
    Registered:
    02 Dec 2015
    02 Apr 2014
    Link to this post

    Hello,

    The Lstring designates this field as being set to "localizable". Check your custom module text field's "More Options" section to see if the "Make localizable" checkbox is selected. If it isn't then you can use string. If it is, then you must use Lstring.

    You can find more information here:

    ~ http://www.sitefinity.com/developer-network/forums/module-builder/undesirable-behavior-dynamiccontent-getvalue-t-(string)

    ~ http://www.sitefinity.com/documentation/ApiReference/webframe.html#topic212601.html

    ~ http://www.sitefinity.com/documentation/api/topic132783.html

    Regards,

    David C
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
5 posts, 0 answered