![](/img/trans.png)
[英]Using AngularJS with ASP.NET MVC ng-repeat is empty in table
[英]Submiting Form that use ng-repeat in ASP.NET MVC
我在angularJS上遇到了一些麻煩,當我將數據匯總為始終為空時,我正在使用ng-repeat顯示該數據,如下所示:
@using (Ajax.BeginForm("UpdateTasks", "Revision", FormMethod.Post, new AjaxOptions { OnSuccess = "OnSaveSuccess" @*, OnBegin="ValidateForm"*@} , new { @id = "participantForm", @class = "form-validation-1" }))
{
<div ng-app="myApp">
<div id="idiv">
<table id="tbl" name="tbl" ng-controller="myCtrl" border="1" style="color:black">
<tr>
<th> Task</th>
</tr>
<tr ng-repeat="x in records">
<td><input type="text" ng-model="x.Question" class="form-control"></td>
</tr>
</table>
<input class="btn m-r-5" type="submit" value="Save" />
這是我的控制器
[HttpPost]
public JsonResult UpdateTasks(object tasks)
{
var tsk = tasks ;
return Json(new { isError ="" }, JsonRequestBehavior.AllowGet);
}
但是對象任務總是空的,我錯過了什么?
您可以嘗試以下操作:首先獲取對象中的所有數據,然后使用ng-repeat以html格式顯示數據/信息。
<table>
<tr ng-repeat="x in records">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
您的代碼有很多錯誤。 讓我們一一開始。
關於您的實際問題,這是因為您尚未將名稱屬性與輸入字段相關聯。 嘗試這樣的事情,讓我知道您是否需要其他指示信息:)
<div ng-app="myApp"> <div id="idiv"> <table id="tbl" name="tbl" ng-controller="myCtrl" border="1" style="color:black"> <tr> <th> Task</th> </tr> <tr> <td ng-repeat="x in records"> <input name="{{x.Question}}" type="text" ng-model="x.Question" class="form-control"> </td> </tr> </table> <input class="btn mr-5" type="submit" value="Save" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.