Developer forum

Forum » Feature requests » Get selected value from item relation list with view model

Get selected value from item relation list with view model

Roald Haahr Jensen
Reply

Hi,

I would like to have the view model extended when used with an radio button / check button / dropdown list, as I see no simple way to retrieve the value for an option.

Here is a simple example: There is a dropdown list with background colors. The way, the name AND value of an option is retrieved, is by a workaround.

var backgroundColorObj = Model.GetValue("BackgroundColor");
var backgroundColorProperty = backgroundColorObj.GetType().GetProperty("SelectedValue");
var backgroundColorValue = backgroundColorProperty.GetValue(backgroundColorObj, null).ToString();

If there is already another way to do this that I have missed, please let me know.

 

Best regards,
Roald, Novicell


Replies

 
Roald Haahr Jensen
Reply
This post has been marked as an answer

Please disregard the request above. As it turns out DW already serves the selected name and value on the ListViewModel. So, rather than calling .GetValue(...), .GetList(...) should be called, which will return the ListViewModel with the properties, I requested, available.

Using that for the background color looks like:

var backgroundColorVm = backgroundColorItem.GetList("BackgroundColor");
var backgroundColorName = backgroundColorVm.SelectedName;
var backgroundColorValue = backgroundColorVm.SelectedValue;

 

Best regards,
Roald

Votes for this answer: 1
 
Nicolai Pedersen
Reply

Thanks for sharing!