<div class="post-text" itemprop="description">
I am following this "http://www.dotnetcurry.com/ShowArticle.aspx?ID=933" thread to to show data on table using knockoutjs,but the table is empty eventhough I see 8 items when I debug the controller.
KnockoutJs function:
viewModel = {
lookupCollection: ko.observableArray()
};
$(document).ready(function () {
$.ajax({
type: "GET",
url: "/Home/GetIndex",
}).done(function (data) {
$(data).each(function (index, element) {
viewModel.lookupCollection.push(element);
});
ko.applyBindings(viewModel);
}).error(function (ex) {
alert("Error");
});
});
HomeController.cs:
public JsonResult GetIndex() { ImplProduct product = new ImplProduct(); return Json(product.findAllProduct()); }
Index View:
<table class="table">
<tr>
<th>Name</th>
<th>Price</th>
<th>Category</th>
<th></th></tr>
<tbody data-bind="foreach: lookupCollection">
<tr>
<td data-bind="text: Name"></td>
<td data-bind="text: price"></td>
<td data-bind="text: Category"></td>
<td><button class="btn btn-success">Edit</button><button class="btn btn-danger">Delete</button></td>
</tr>
</tbody>
</table>
thankyou very much your answer.
</div>