请帮助我如何在数组中保存数据并在表格内的表中显示
<div ng-app="farmerapp" ng-controller="RegController">
@Html.TextBoxFor(x => x._Cetificate.CertificateName,new { data_ng_model = "_Cetificate.CertificateName"})
@Html.ValidationMessageFor(x => x._Cetificate.CertificateName)<br />
@Html.TextBoxFor(x => x._Cetificate.Year, new { data_ng_model = "_Cetificate.Year" })
@Html.ValidationMessageFor(x => x._Cetificate.Year) <input type="button" class="btn btn-sm btn-primary" id="Btncertification" ng-click="GetFormerData()" value="Save Certificat" />
<table>
<tr ng-repeat="abc in MYdata">
<td>{{abc.CertificateName}}</td>
<td>{{abc.Year}}</td>
</tr>
</table>
我的js代码
$scope.GetFormerData = function () {
$scope.MYdata = [];
$scope.MYdata.push($scope._Cetificate);
}
请在这里为我提供全新的帮助
答案 0 :(得分:0)
您有2种选择。
最简单的一种方法(我建议)是对API(在RegController
内部)进行ajax调用,以获取您的数据,然后将结果放入MYData
中。
另一种选择是使用Razor的Html.Raw()
$scope.MYData = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.DataValues));