Reputation: 3502
I am binding select list in knockout
Html:
<select data-bind="options: $parent.Languages, optionsValue:function(item) { return item.Value; }, optionsText: function(item) {return item.Text; }, value: LanguageID, valueUpdate: 'change'" />
on submit ==> var data = ko.mapping.toJS(viewModel1);
Controller:
Languages = new SelectList(this.Languages(), "ID", "LanguageName", SelectedLanguageID);
It returns the complete object in LanguageID = "Selected: true, ID: 1, LanguageName: "English" but i want that it should return only ID like LanguageID = 1
I already use subscribe method and assign
Upvotes: 0
Views: 2400
Reputation: 114792
A few things:
Make sure that you properly open/close your select
like: <select></select>
You can simplify your optionsText
and optionsValue
specifications by just passing the property name that you want as a string (<select data-bind="options: Languages, optionsValue: 'Value', optionsText: 'Text', value: LanguageID" ></select>
)
You do not need to use valueUpdate
on a select
Otherwise, it seems to be working properly.
Here is a sample: http://jsfiddle.net/rniemeyer/dgmV6/
Upvotes: 5