我的做法如下:
www.un.org/Depts/DGACM/index_spanish.htm 为一揽子浏览(PackageRow.cshtml)创建部分
@model IEnumerable<PackageViewModel>
<div class="editorRow">
@using (Html.BeginCollectionItem("packages"))
{
@Html.TextBoxFor(x => x.WhateverYouNeed)
}
</div>
www.un.org/Depts/DGACM/index_spanish.htm 在用户选择浏览量时,通过jax将包装分成如下:
@Html.ActionLink("Go!", "AddPackages", null, new { id = "addPackages" })
<div id="editorRows"></div>
<script type="text/javascript">
$(document).ready(function () {
$("#addPackages").click(function () {
$.ajax({ url: this.href, cache: false, success: function (html) {
$("#editorRows").append(html); // add the number of rows you need here
}
}); return false;
});
$("a.deleteRow").live("click", function () { $(this).parents("div.editorRow:first").remove(); return false; });
});
</script>
www.un.org/Depts/DGACM/index_spanish.htm 通过你的控制器添加部分内容:
public ActionResult AddPackages()
{
return PartialView("PackageRow", new PackageViewModel { ... });
}
www.un.org/Depts/DGACM/index_spanish.htm Save the data
[Authorize]
[HttpPost]
public ActionResult CreatePackages(int id, FormCollection fc)
{
int nrKeys = fc.AllKeys.Count();
int i = 0;
int interations = (nrKeys / 2);
foreach (var key in fc.AllKeys)
{
if (nrKeys <= i)
break;
if (i != 0)
{
string value1 = fc[i];
string value2 = fc[i + 1];
...
}
else
{
i++;
}
...