I encountered an error with my web application that is using Knockout.js
Received the error message: "Cannot use 'in' operator to search for 'length'"
This is my Code:
$(document).ready(function () {
AjaxRequest();
});
function AjaxRequest() {
$.post("../../Api/DisabilitiesHandler.ashx?method=get", function (data) {
var viewModel = {
disabilities: ko.observableArray(data)
};
ko.applyBindings( viewModel, document.body);
});
}
<table>
<tbody data-bind="template: { name: 'disabilitiesRowTemplate', foreach: disabilities }"></tbody>
</table>
<script type="text/html" id="disabilitiesRowTemplate">
<tr>
<td>Name:
<input data-bind="value: Name" /></td>
<td>
Active <input type="checkbox" data-bind="checked: Active" /></td>
</tr>
</script>
This represents my model
public class Disabilities
{
public int Id { get; set; }
public string Name { get; set; }
public bool Active { get; set; }
}
Here is a snippet of the web service code
context.Response.ContentType = "application/JSON";
DbsaDal.Entities.DBSAEntities db = new DbsaDal.Entities.DBSAEntities();
List<DbsaDal.Model.Disabilities> disabilities = DbsaDal.Entities.Disabilities.Get(db);
context.Response.Write(new JavaScriptSerializer().Serialize(disabilities));
If you have any advice or suggestions, please let me know. I've tried searching online without success
Update 1:
An uncaught TypeError occurred: "Cannot use 'in' operator to search for 'length' in [{"Id":1,"Name":"Blind","Active":false},{"Id":2,"Name":"Mute","Active":true}]"