jQWidgets Forums

jQuery UI Widgets Forums Lists ComboBox Find value – MVC model

This topic contains 2 replies, has 2 voices, and was last updated by  Justintkw 9 years ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Find value – MVC model #83276

    Justintkw
    Participant

    Hello:

    When I select an item from the combo box using a hardcoded value, lie: $(‘#SomeName’).jqxComboBox(‘val’, “1”) It works. However, I my MVC5 form is bound to a model, and there is a particular property (Model.TheValue) the value of which I want the combo box to try to select.

    I tried: $(‘#SomeName’).jqxComboBox(‘val’, @Model.TheValue), but that doesn’t work. I get an error saying that ‘Model’ is undefined. Can you please help me by showing how to select an item using MVC model?

    Thanks a bunch!

    Justin

    Find value – MVC model #83289

    Peter Stoev
    Keymaster

    Hi Justin,

    Probably it is not defined if the error is what you explain it is. My suggestion for you is to debug this part of your code.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Find value – MVC model #83304

    Justintkw
    Participant

    Hi Peter:

    I have corrected the code, yet I still can’t get the combo box to select the item I want. My script is below. I would appreciate some help on this.

    Thanks!

    <script type=”text/javascript”>
    $(document).ready(function () {
    var data = @Html.Raw(Model.JSON_Str_Of_NonYTCBand); //Confirmed that the data is there. The combo box is loaded with the data.
    var PreselectedValue = “@Model.List_Of_StdDemo_DataObj[0].NonYTCBand”
    //alert(PreselectedValue); confirmed that the value is returned and that it is on th list.
    $(“#jqx_NonYTCBand_Combo”).jqxComboBox({ source: data, displayMember: “displayName”, valueMember: “code”, width: 150, height: 25 });
    $(“#jqx_NonYTCBand_Combo”).on(‘bindingComplete’, function (event) {
    var item = $(“#jqx_NonYTCBand_Combo”).jqxComboBox(‘getItemByValue’, PreselectedValue);
    $(“#jqx_NonYTCBand_Combo”).jqxComboBox(‘selectItem’, item ); //No error thrown, but the item is NOT selected.
    });
    });
    </script>

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.