【发布时间】:2011-12-07 01:02:25
【问题描述】:
我的 ViewResult 控制器:
public ViewResult Controller(int id)
{
List<Data> dataList = dataAccess.getDataById(id);
Results[] resultArray = new Results[dataList.Count];
ViewBag.results= resultArray;
return View(dataList);
}
我的观点:
@model IEnumerable<Solution.Models.Data>
@{
Solution.Models.Results[] res= ViewBag.results;
}
@using (Html.BeginForm()) {
<table>
@{
int i = 0;
foreach (var item in Model) {
<tr>
<td>
Snippet: @Html.DisplayFor(modelItem => item.text)
</td>
</tr>
<tr>
<td>
Translation: @Html.EditorFor(modelItem => res[i].text)
</td>
</tr>
i++;
}
}
</table>
<p>
<input class="CRUD-buttons" type="submit" value="Send" />
</p>
}
我的控制器 ActionResult:
[HttpPost]
public ActionResult Controller(/*List<Data> dataList, */Results[] results)
{
ResultText = results[0].text; //NullReferenceException
}
dataList 和结果为空。我在 stackoverflow 上阅读了几篇文章,但找不到解决方案。
我已经查看了以下博客 (link),但它的 MVC 2 代码。 :(
【问题讨论】:
-
请不要在标题前加上“C# MVC 3:”。这就是标签的用途。
标签: c# asp.net-mvc-3 list view controller