ModelView returns value or dataItem

2 posts, 0 answers
  1. Grant
    Grant avatar
    179 posts
    Member since:
    Jul 2016

    Posted 14 Oct 2019 Link to this post


    Please see my dojo for context,

    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.


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


  2. Aleksandar
    Aleksandar avatar
    280 posts

    Posted 15 Oct 2019 Link to this post

    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.

    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.
Back to Top