Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Presenting backend data using AngularJS/AJAX in MVC VIEW

@*Use a table to display the data.*@
<div ng-app="myApp" ng-controller="myCtrl">
    <table class="table">
        <thead>
            <tr>
                <th>
                     Id
                </th>
                <th>
                    Name
                </th>
                <th>
                     SelectedState
                </th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="x in articles">
                <td>{{ x.id }}</td>
                <td>{{ x.name }}</td>
                <td>{{ x.selectedState }}</td>
                <td>button</td>
            </tr>
        </tbody>
    </table>
</div>

@section Scripts{
     @*add the angularjs reference*@
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
    <script>
        var app = angular.module('myApp', []);
        app.controller('myCtrl', function ($scope, $http) {
            //call the action method to get all data, then assign the response data to the model.
            $http.get("/Article/GetAllArticles").then(function (response) {
                $scope.articles = response.data;
            }); 
        });  
    </script>
}
Comment

Presenting backend data using AngularJS/AJAX in MVC VIEW

public IActionResult GetAllArticles()
    {   //query database to get all article with state.
        var articles = new List<Article>(){
            new Article() { Id = 1, Name = "A", SelectedState = "Open" },
            new Article() { Id = 2, Name = "B", SelectedState = "Scheduled" },
             new Article() { Id = 3, Name = "C", SelectedState = "Closed" },
        };
        return Json(articles);
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: when selecting second dropdown ng-model object return null 
Javascript :: convert base64 formatted data to image using AngularJs 
Javascript :: Relaxed "angularjs" style expression parsing missing in vue 
Javascript :: Calculating state happens to late 
Javascript :: React Native : Add a band of color in the background 
Javascript :: When doing a booking system, where would it be better to do? Back end or front end 
Javascript :: Difficulties handling asynchronous taks using image-picker and copying files in react-native 
Javascript :: What is the best way to download mulitple images using jquery 
Javascript :: javascript include array value in an object property in an array map some 
Javascript :: How to change a key value pair within a nested json structure C# 
Javascript :: sending api with limited fields in express 
Javascript :: Using javascript code in Jade views - if(variable) shows undefined instead of passing 
Javascript :: select the value of dropdownMenu with Semantic ui react 
Javascript :: Sequelize conditional shorthands 
Javascript :: echarts js 
Javascript :: Remove # id From URL When Clicked On Href Link 
Javascript :: phaser time event start at 
Javascript :: 120. Triangle - JavaScript Solution With Explantion 
Javascript :: how to get content disposition from header jquery 
Javascript :: JavaScript: Cycle through three-state checkbox states 
Javascript :: css to jss 
Javascript :: success res node.js 
Javascript :: regex specific number of characters 
Javascript :: jQuery mobile anchor link on the same page 
Javascript :: mongodb function example 
Javascript :: wait untill 2 
Javascript :: Backbone Get Model From Collection 
Javascript :: ES6 reactjs problems 
Javascript :: convert string to number 
Javascript :: fs 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =