jQuery UI Widgets › Forums › General Discussions › Lists › ComboBox › Find value – MVC model
Tagged: combobox, javascript combobox, jquery combobox
This topic contains 2 replies, has 2 voices, and was last updated by Justintkw 9 years, 9 months ago.
-
AuthorFind value – MVC model Posts
-
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
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 StoevjQWidgets Team
http://www.jqwidgets.comHi 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> -
AuthorPosts
You must be logged in to reply to this topic.