【发布时间】:2015-01-30 14:07:16
【问题描述】:
这是我的视图模型:
public class TaskViewModel{
public int TaskID{get;set;}
public IEnumerable<TaskExecutor> Executors{get;set;}
}
public class TaskExecutor{
public int ExecutorID{get;set;}
public string LastName{get;set;}
public string FirstName{get;set;}
}
在我看来,我做过这样的事情:
<table>
@foreach(var item in Model.Executors)
{
<tr>
<td>item.ExecutorID</td>
<td>@string.Format("{0} {1}",item.FirstName,item.LastName)</td>
</tr>
}
</table>
现在,在加载视图时,不会有任何问题,但我可能需要编辑表格,并且我希望在提交表单时保留更改。我能想到的唯一方法是 HtmlHelper 扩展方法,它将正确地将 IEnumerable 绑定到表,但我不知道该怎么做。我很高兴看到一些代码。或者还有其他方法可以实现吗?
【问题讨论】:
-
“我可能需要编辑表格并且希望在提交表单时保留更改”是什么意思?您是在谈论编辑表中的值并在后续请求之间保留这些更改吗?
-
您可能对this article感兴趣
-
抱歉,@ChrisPratt,我遇到了互联网问题。是的,我的意思是。
-
@StephenMuecke,您一如既往地乐于助人。那篇文章似乎正是我所需要的。谢谢。
标签: asp.net-mvc html-table ienumerable model-binding