How to bind grid using angularjs in mvc?

How to bind grid using angularjs in mvc?, someone asked me to explain?

In this article we will discuss how to bind the grid using angularjs in mvc c#. On the page load bind the data from database and display using angular ui datagrid.

Create a controller in a project named as product and create a json method Get data(GetProdut() ). 

Here I am using Northwind database. You can download it from following link.

Download Northwind Database

Open Microsoft sql management studio and right click on the database and attach it.

Step 1: Create an entity data model using table Product and generate entity for that.

Step 2: Right click on the "Controllers" folder and add "Product" controller. Copy and paste the following code.

  public class ProductController : Controller
        // GET:/Product/
        models db = new models();
        public ActionResult Index()
            return View();

       public JsonResult GetProduct()
            var products = (from product in db.Products.AsEnumerable()
                            select new
                                Name = product.ProductName,
                                UnitPrice =product.UnitPrice,
                                QuantityPerUnit= product.QuantityPerUnit

           return Json(products, JsonRequestBehavior.AllowGet);

Step 3:  Copy and paste the following code in the design page index.cshtml. I used cdn for angularjs and jQuery ui datagrid.

    ViewBag.Title = "Angular UI Grid Tutorial";
    .grid {
        width: 50%;
<h2>Angular UI Grid</h2>
<script src="//"></script>
<script src=""></script>
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href="" type="text/css">
<script type="text/javascript">
    var app = angular.module('mvcapp', ['ngTouch', 'ui.grid']);
    app.controller('DemoController', function ($scope, $http) {
        $scope.gridOptions = {
            enableSorting: true,
            rowHeight: 100,
            columnDefs: [
              { field: 'Name' },
              { field: 'UnitPrice' },
              { field: 'QuantityPerUnit' }
        $http.get('/Product/GetProduct').success(function (data) {
            $ = data;

<div ng-app="mvcapp" ng-controller="DemoController">
    <div id="grid1" ui-grid="gridOptions" class="grid"></div>


angular ui datagrid

Post your comments / questions