This is a migrated thread and some comments may be shown as answers.

ModelView returns value or dataItem

1 Answer 63 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Grant asked on 14 Oct 2019, 08:38 AM

Hi,

Please see my dojo for context, https://dojo.telerik.com/AdIqAPoy

The modelView binds 'selectedName' to the value of the dropdownlist, my query is this:
1) Why, when I select a option and 'get' the value, does the ModelView return the dropdownlist dataItem, but

2) when I 'set' the value of 'selectedName' manually, to the id of a dataItem, the dropdownlist updates, but when I 'get' the value again, it returns the id only?

Version v2018.3.911.

Thanks,
Grant

PS. In the Forums, whats the difference between the 'MVVM' and 'ModelView' topics?

 

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 15 Oct 2019, 02:55 PM

Hi Grant,

Thank you for the provided dojo. Note that you need to define the valuePrimitive field that specifies the value binding behavior for the widget when the initial model value is null if you would like to ensure the widget is correctly bound to the item, but not the item's value field. If set to false, the View-Model field will be updated with the selected item. However, when setting the widget value you need to set it to the particular object, but no the id of the object. You can find an example in this dojo.

Alternatively, if the valuePrimitive is set to true the data-value-field attribute will specify the field of the current item to which the option value is bound. You can find an example in this dojo.

For further details on binding widgets to MVVM provides I would suggest the following section from the documentation.

I hope this helps. Let me know if you have further questions.

Regards,
Aleksandar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
MVVM
Asked by
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Aleksandar
Telerik team
Share this question
or