How to know what type for dynamic content?
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?
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"
);
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
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.
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:
~ www.sitefinity.com/.../undesirable-behavior-dynamiccontent-getvalue-t-(string)
~ www.sitefinity.com/.../webframe.html
~ www.sitefinity.com/.../topic132783.html
Regards,