I want to get List of employees, after clicking on button Get Data. But JS script does not invoke public JsonResult GetData.
Why js do not invoke
public JsonResult GetDatawhere is mistake?How to pass argument in 'public JsonResult GetData(int id)'?
HomeController:
namespace AngularJS.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult GetData(int id)
{
List<Employee> employees = new List<Employee>();
employees.Add(new Employee{Name="Jhon"});
employees.Add(new Employee{Name="Rick"});
return Json(employees, JsonRequestBehavior.AllowGet);
}
}
public class Employee
{
public string Name { get; set; }
}
}
MyScript.js
var app = angular.module("myApp", []);
app.controller("calendarDemo", function($scope) {
$scope.count = 0;
$scope.getData = function () {
$http({ method: 'GET', url: '/Home/GetData' }).
success(function (data, status, headers, config) {
//$scope.Employees = [{ name: 'Jhon' }, { name: 'Rick' }];
}).
error(function (data, status, headers, config) {
alert('error');
});
}
});
Index.cshtml:
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script src="~/Scripts/CustomScripts/MyScript.js"></script>
<script src="~/Scripts/moment.js"></script>
<link rel="stylesheet/less" type="text/css" href="~/Scripts/CustomScripts/style.less">
<script src="~/Scripts/less-1.5.1.js" type="text/javascript"></script>
<li ng-repeat="employee in Employees">
{{employee.name}}
</li>
<button ng-click="getData()">Get Data</button>
angular.js? I can't see it.