Girish kumar Gorantla
Girish kumar Gorantla

Reputation: 36

Not able to get the data from asp.net mvc controller to angularjs using ajax call

i am able to hit the controller method and able to return the data

[HttpPost]
    public JsonResult GetAppsList()
    {          
        var Apps = DataModel.ApplicationMasters.ToList();
        return Json(new { appslist = Apps }); 
       // return AppsList;
    }

but in angular js not able to get the data

myApp.controller('SpicyController', ['$scope','$http', function ($scope,$http) {    
$http({
    method: 'POST',
    url: 'Home/GetAppsList'
}).then(function (response) {
$scope.appslist = response.data.appslist; }, function (error) {console.log(error);});}]);

in view

<div class="main" ng-app="spiceApp">
    <div ng-controller="SpicyController"> 
        <table>          
            <tr ng-repeat="app in appslist">
                <td>
                    {{app.Name}}
                </td>
            </tr>
        </table>
       </div>
    </div>

can you help me why i am not able to display result?

Upvotes: 0

Views: 317

Answers (1)

Ghanshyam Singh
Ghanshyam Singh

Reputation: 1381

<div class="main" ng-app="spiceApp">
<div ng-controller="SpicyController"> 
    <table>          
        <tr ng-repeat="(index,data) in appslist">
            <td>
                {{data.Name}}
            </td>
        </tr>
    </table>
   </div>
</div>

applist is an Object . To Apply ng-repeat on an Object write this ng-repeat=(index,data) in applist.

myApp.controller('SpicyController', ['$scope','$http', function ($scope,$http) {    
$http({
    method: 'POST',
    type:'json',
    url: 'Home/GetAppsList'
}).then(function (response) {
$scope.appslist = response.data.appslist; }, function (error) {console.log(error);});}]);

Upvotes: 1

Related Questions