我是Angular的新手,也是ASP.NET MVC的新手。我已经成功地将我的服务器模型传递给我的AngularJS控制器。但是,我希望能够在将模型传递给AngularJS控制器之前对其进行编辑。
我将如何实现这一目标? 非常感谢任何帮助!
我的观点:
...
@if (Model != null)
{
<table class="table">
@for (var index = 0; index < Model.Fields.Count; index++)
{
<tr>
<td>@Html.DisplayTextFor(m => Model.Fields[index].Title)</td>
<td>@Html.EditorFor(m => Model.Fields[index].Value)</td>
</tr>
}
</table>
}
...
<form class="form-horizontal" role="form" ng-submit="posta(@System.Web.Helpers.Json.Encode(Model))">
<div>
<ul>
<li ng-repeat="article in articles">
{{ article.Article.itemNumber | uppercase }} - {{ article.Article.itemDescription | lowercase }}
</li>
</ul>
</div>
<div class="form-group">
<div style="padding-left:110px">
<input type="submit" value="OK" class="btn btn-primary" />
</div>
</div>
</form>
控制器:
var myApp = angular.module("ArticleApp", []);
myApp.controller("articleController", function ($scope) {
$scope.articles = [
{
Article: {
itemNumber: '1234',
itemDescription: 'Test'
}
},
{
Article: {
itemNumber: '5678',
itemDescription: 'Test2'
}
}
];
$scope.addRow = function () {
$scope.articles.push({
Article: {
itemNumber: '2222',
itemDescription: 'asdasd'
}
});
};
$scope.posta = function (model) { //Model does not contain changes :(
var m = $scope.articles;
}