0

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?

11
  • Check network traffic and look at what data is being returned from your controller. Should help you figure it out. If I had to guess (and I do), it's a casing issue. Commented Jan 10, 2017 at 12:43
  • i don't know how to check network traffic for my application, can you help me out? Commented Jan 10, 2017 at 12:49
  • in your browser, press F12. It'll open developer tools. On of the tabs will be network. If chrome, it's already running, just take a look. If IE, press the start button to start capturing. if another browser, you'll have a bit of research to do. Commented Jan 10, 2017 at 12:53
  • Thanks Mike i am getting below error Commented Jan 10, 2017 at 13:04
  • angular.js:7918 GET localhost:37481/Home/GetAppsList 500 (Internal Server Error) (anonymous) @ angular.js:7918 C @ angular.js:7750 f @ angular.js:7484 C @ angular.js:10725 C @ angular.js:10725 (anonymous) @ angular.js:10811 $eval @ angular.js:11726 $digest @ angular.js:11554 $apply @ angular.js:11832 (anonymous) @ angular.js:1297 d @ angular.js:3678 c @ angular.js:1295 Xb @ angular.js:1309 Sc @ angular.js:1258 (anonymous) @ angular.js:20364 a @ angular.js:2336 (anonymous) @ angular.js:2604 q @ angular.js:300 c @ angular.js:2603 Commented Jan 10, 2017 at 13:05

1 Answer 1

1
<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);});}]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.