模型绑定到列表 - 如何处理插入
问题描述:
我指的是菲尔哈克的这篇文章http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx我需要做同样的事情,但如果我需要在列表中插入记录,在我想要的任何索引处如何?如何保持索引的同步不会做一些JavaScript并更新所有索引?模型绑定到列表 - 如何处理插入
<form method="post" action="/Home/Create">
<input type="text" name="[0].Title" value="Curious George" />
<input type="text" name="[0].Author" value="H.A. Rey" />
<input type="text" name="[0].DatePublished" value="2/23/1973" />
<input type="text" name="[1].Title" value="Code Complete" />
<input type="text" name="[1].Author" value="Steve McConnell" />
<input type="text" name="[1].DatePublished" value="6/9/2004" />
<!-- I want to insert a record here by adding the fields through JavaScript -->
<input type="text" name="[2].Title" value="The Two Towers" />
<input type="text" name="[2].Author" value="JRR Tolkien" />
<input type="text" name="[2].DatePublished" value="6/1/2005" />
<input type="submit" />
我不太明白,我怎么会用在该博客文章做的东西,如插入记录,以特定指数所描述的“非循序索引”。
任何想法?
问题是,我不能将我的项目列表作为从视图中回传的模型。我需要额外的数据,因此项目列表是我的模型中的一个列表。所以做他所描述的不适合我。我需要它的索引发布到我的模型列表中? – lahsrah 2010-11-10 21:46:54