Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to pass the json data from controller to angularjs..i have tried the below code but just only show the table header don't show my product data..below put my code.. this is my angularjs code..

 $scope.ViewPro = function () {    
    $http({ method: 'GET', url: 'AddToCart/ProList' }).
    success(function (p) {
        debugger;            
        console.log(p);
        $scope.Products = p; // Response Data                 
        $location.path('/ViewProduct');
    }).
    error(function (data) {
        alert(data + "Error");
        console.log(data);
    });
};


this is my json controller method..

public JsonResult ProList()
   {
       var ProductList = db.tblProducts.ToList();
       var Products = ProductList.Select(d => new
       {
           d.ProductId,
           d.ProductName,
           d.Price,
           d.Descripation,
           d.SEOURL,
           d.Image,
           d.IsPubliesd,
       }).ToList();
       return Json(Products, JsonRequestBehavior.AllowGet);
   }


this is my routeProvider

.when('/ViewProduct', { templateUrl: 'AddToCart/ViewProduct' })


this is my view..

<div ng-app="MyApp" ng-controller="AddToCart" ng-model="AddToCart"> 
    <div class="table-responsive">
        <table class="table table-striped table-bordered">
            <tr>
                <td align="center">ProductId</td>
                <td align="center">ProductName</td>
                <td align="center">Descripation</td>
                <td align="center">Price</td>
                <td align="center">SEOURL</td>
                <td align="center">IsPubliesd</td>                    
                <td align="center">AddToCart</td>
            </tr>
            <tr ng-repeat="Product in Products">
                <td ng-bind="Product.ProductId"></td>
                <td>{{Product.ProductName}}</td>
                <td>{{Product.Descripation}}</td>
                <td>${{Product.Price}}.00</td>
                <td>{{Product.SEOURL}}</td>
                <td>{{product.ispubliesd}}</td>                                      
            </tr>
        </table>
    </div>     
</div>


What I have tried:

i want to show my product data but i get the error just only show table header don't show my data i tried the above code but i am not get perfect result so please any one idea so please help me..
Posted
Comments
Sinisa Hajnal 14-Apr-16 2:38am    
Does your ProductList contain any data? Does your Products after LINQ? Start from the beginning and step through the application until you find the problem.

Also, when you ask about problems which produce errors, it is helpful to include error message in the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900