Developer forum

Forum » Development » Viewmodel question

Viewmodel question

Harald Brouwers
Reply

Hi,

A question here, we have created an item, which uses another item (Buttonlink) as a field:

This item is a ItemViewModel in my template (Dynamicweb.Frontend.ItemViewModel).
The ItemViewModel has a Field "Target" (Dynamicweb.Frontend.ItemFieldViewModel).

This Field is a Dropdown list in the backend:

I can get the Field value with:

Model.Item.GetItem("ButtonLink").GetField("Target").GetValue()

This gives me the Label value (Nieuw tabblad) of the item in the dropdown list:

What I need is the value of the Value field (_blank), but I cant figure out how to get this value.
Can you help me out here?

Greetings Harald


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

Hi Harald,

Your code...

Model.Item.GetItem("ButtonLink").GetField("Target").GetValue()

This actually returns a list view model (Dynamicweb.Frontend.ListViewModel). You only see the label value in the rendered output because that is its string representation.

You can use one of the following methods to get the selected value...

Model.Item.GetItem("ButtonLink").GetField("Target").GetList().SelectedValue
Model.Item.GetItem("ButtonLink").GetList("Target").SelectedValue

Best regards,
Morten

Votes for this answer: 1
 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Harald

Instead of GetValue(), call GetList() - that will give you a collection of the options i a ListViewModel.

ListViewModel: https://doc.dynamicweb.com/api/html/e1f80b6f-5824-3c23-11fc-9d441a956d00.htm

All the possibilities of ItemViewModel: https://doc.dynamicweb.com/api/html/0c4728a9-44bb-4cef-af09-c1e30c5fcb08.htm

BR Nicolai

Votes for this answer: 1
 
Harald Brouwers
Reply

Hi guys,

Thanks for the quick reply, I got it working now :)

Greetings Harald

 

You must be logged in to post in the forum