I am using MVC with KnockoutJs and facing an issue with a value
binding.
@Html.DropDownListFor(m => m.PrimarySubspecialty, Model.PrimarySubspecialties, new { id = "ddUserDetailsPrimarySubSpeciality", style = "width:245px;height:25px;", @class = "nmc-select", data_bind = "options: primarySubSpecialities,optionsText: 'Name',optionsValue: 'Id',value:PrimarySubspecialty" })
I am not sure why the PrimarySubspecialty
value in the model is not getting bound to the dropdown selected value.
Here is my js code:
this.PrimarySubspecialty = Ko.observable($('#ddUserDetailsPrimarySubSpeciality').val());
this.primarySubSpecialities = ko.observableArray([]);
function loadPrimarySubSpecilaities() {
$.ajax({
type: 'GET',
url: primarySubSpecialityUrl,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
processdata: false,
cache: false,
success: function (data) {
primarySubSpecialities = [];
try {
if (data.length == 0) {
primarySubSpeacilityDropdownId.empty();
}
model.primarySubSpecialities(data);
}
});
}
Please let me know how I can set the value to PrimarySubSpeciality
dropdown.