Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

knockoutjs can not show data

$
0
0

<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>


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>