I'm using the DTP List Picker frequently in Umbraco projects because of the possibility to set custom values. However in my latest project I also need to get the prevalues - text and value - programmatically in an mvc controller. To do that with a standard Umbraco radiobuttonlist, for example, is quite straightforward, but the DTP List Picker beats me. I've tried to serialize and deserialize the json back and forth but without luck. Is there anyone having succeeded with this and kind enough to provide some sample code?
I address myself directly to you since you, as the project owner, should be able to help me on this matter, if any.
I need to bring up the text and value properties from a number of DTP List Picker datatypes. But I don't seem to be able to deserialize the json correctly in my Mvc Controller (see postings above).
I would be most thankful if you take the time to show me the working code.
Tested this and it works, no null checks but something to build on
Class 1
public class DTPPreValue
{
[JsonProperty(PropertyName = "type")]
public string Type { get; set; }
[JsonProperty(PropertyName = "items")]
public List<DTPItem> Items {get; set;}
}
Class 2
public class DTPItem
{
[JsonProperty(PropertyName = "checked")]
public bool Checked { get; set; }
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }
[JsonProperty(PropertyName = "value")]
public string Value { get; set; }
}
How to get prevalues from DTP List Picker
Hi,
I'm using the DTP List Picker frequently in Umbraco projects because of the possibility to set custom values. However in my latest project I also need to get the prevalues - text and value - programmatically in an mvc controller. To do that with a standard Umbraco radiobuttonlist, for example, is quite straightforward, but the DTP List Picker beats me. I've tried to serialize and deserialize the json back and forth but without luck. Is there anyone having succeeded with this and kind enough to provide some sample code?
/Jan
Is this any different from what you already have? What does the json you are trying to deserialize look like?
Thanks for your interest in my problem, Ian.
I'm fetching the prevalues just like you do - by using the DataTypeServices GetPreValuesByDataTypeId method.
The content of the preValues variable is, according to Visual Studio's Text Visualizer:
It's when trying to deserialize this json into a C# list, from where I can take it further, I fail. Can you help?
/Jan
Hi Jason,
I address myself directly to you since you, as the project owner, should be able to help me on this matter, if any.
I need to bring up the text and value properties from a number of DTP List Picker datatypes. But I don't seem to be able to deserialize the json correctly in my Mvc Controller (see postings above).
I would be most thankful if you take the time to show me the working code.
/Jan
Tested this and it works, no null checks but something to build on
Class 1
Class 2
View
Type property could also be made into an enum on your model.
If this doesn't work for you I suggest there must be some other issue with your project, if so maybe try re-installing the package.
It works fine. Many thanks for the help. /Jan
is working on a reply...