CSharp · Mvc
using System;
using System.ComponentModel.DataAnnotations;
namespace HelloWorldMvcApp
{
public class Customer
{
public int Age
{
get;
set;
}
public int Id
{
get;
set;
}
//See here for list of answers
public string Comments
{
get;
set;
}
public string Name
{
get;
set;
}
}
}
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<!-- CSS Includes -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style type="text/css">
.field-validation-error {
color: #ff0000;
}
</style>
</head>
<body>
<div class="container">
<div ng-app="app" ng-controller="angularController">
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items">
<td>{{item.Id}}</td>
<td>{{item.Name}}</td>
<td>{{item.Age}}</td>
<td>{{item.Comments}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- JS includes -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/mvc/4.0/jquery.validate.unobtrusive.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<script type="text/javascript">
angular
.module('app', [])
.controller('angularController', function ($scope, $http) {
$http.get('@Url.RouteUrl(new{ action="GetCustomers", controller="Home"})')
.success(function (data) {
$scope.items = data;
});
});
</script>
</body>
</html>
using System;
using System.Web.Mvc;
using System.Collections.Generic;
namespace HelloWorldMvcApp
{
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
return View(new Customer());
}
public JsonResult GetCustomers()
{
Customer[] customers = new Customer[]
{
new Customer
{
Age = 52, Comments = "Hello World", Id = 1, Name = "Andrew Max"
}
, new Customer
{
Age = 12, Comments = "Hello World", Id = 2, Name = "Michael Hearve"
}
, new Customer
{
Age = 54, Comments = "Hello World", Id = 3, Name = "Best Regards"
}
, new Customer
{
Age = 33, Comments = "Hello World", Id = 4, Name = "Andrea Lucy"
}
, new Customer
{
Age = 46, Comments = "Hello World", Id = 5, Name = "Silvia Reagen Estongard"
}
, new Customer
{
Age = 23, Comments = "Hello World", Id = 6, Name = "James Hall"
}
, new Customer
{
Age = 43, Comments = "Hello World", Id = 7, Name = "Pak Marsudi"
}
, new Customer
{
Age = 22, Comments = "Hello World", Id = 8, Name = "Gilbert Silalahi"
}
, new Customer
{
Age = 52, Comments = "Hello World", Id = 9, Name = "Noni Cukong"
}
}
;
return Json(customers, JsonRequestBehavior.AllowGet);
}
}
}