Hi i want to save the selected value of a drop down to the
server , But every time it is returning same value not the updated value
which i selected.
My ko:
var stateModel = {
CountriesList: ko.observableArray([]),
StateId: ko.observable(),
StateName: ko.observable('').extend({ required: true }),
ShortName: ko.observable('').extend({ required: true }),
IsActive: ko.observable(true),
CountryId: ko.observable()
var stateViewModel = function () {
var self = this;
self.StateModel = stateModel;
self.CountriesList = ko.observableArray([]);
self.StatesList = ko.observableArray([]);
self.CountryId = ko.observable();
am calling this Add State in a button click, But every time it is returing in args like:
{"argBO":{"CountriesList":[],"StateName":"asdf","ShortName":"s","IsActive":true}}
self.AddState = function () {
var args = JSON.stringify({ argBO: jQuery.parseJSON(ko.toJSON(self.StateModel)) });
alert(args);
ajax.Post("AddState.aspx/AddState", args, false).success(function (data) {
if (data.d[0] > 0) {
logger.success(data.d[1]);
}
else {
logger.error(data.d[1]);
}
});
}
var vm = new stateViewModel();
ajax.Get("AddCountry.aspx/getCountries", { IsActive: true }, false).success(function (data) {
for (var i = 0; i < data.d.length; i++) {
vm.CountriesList.push(data.d[i]);
}
});
ko.applyBindings(vm, document.getElementById("divcountry"));
ko.applyBindings(stateViewModel, document.getElementById("state_container"));
var vm1 = new stateViewModel();
ajax.Get("AddState.aspx/getStates", { IsActive: true }, false).success(function (data) {
vm1.StatesList(data.d);
});
Dropdown is in divcountry, and StateName,ShortName are in
state_containerdiv..Actually i have dummy label in divCountry beside
DropDown which is giving me correct selected value depending on the
Dropdown selection...
<div id="divcountry">
<select data-bind="options: CountriesList,optionsText: 'CountryName',optionsValue:'CountryId',value:CountryId,optionsCaption: 'Select Country..'" style="width: 148px">
</select>
<label data-bind="text: CountryId"></label>
</div>