【发布时间】:2020-06-14 17:17:44
【问题描述】:
我有一个 MVC 应用程序,我从 MVC 控制器获取数据并使用 angular 将其作为 JSON 传递给 View。数据字段之一是日期时间值。在控制器端,日期字段以 {5/27/2019 12:00 AM) 格式显示,但当它在角度端时,相同的日期字段显示例如:/Date(864511200000)/
我已尝试使用将 /Date(864511200000)/ 转换为 {MM/dd/yyyy} 的短日期
<td>{{employee.DateOfBirth | date:'shortDate'}}</td>
但它不会工作。我的控制器方法
public JsonResult GetEmployees()
{
var employees= db.Employees.ToList();
return Json(employees, JsonRequestBehavior.AllowGet);
}
角度代码
myApp.controller('EmployeeCtrl',function ($scope, $http) {
$http({
method: 'GET',
url: '/Employees/GetEmployees'
}).then(function (response) {
$scope.employees= response.data;
console.log(response.data);
});
});
我的查看代码:
<tr ng-repeat="employee in employees">
<td>{{employee.DateOfBirth | date:'shortDate'}}</td>
//其余代码
【问题讨论】:
标签: asp.net angularjs database datetime model-view-controller