我有一个模型,我在视图中实现了。数据传递给控制器,我使用控制器中的表单集合检索值。我共有50条记录,每页显示10条记录。问题是,当我试图选中全部选中复选框时,所有50条记录都被选中。但是当我提交时,在控制器中,表单集合只有当前的第10页记录ID。其余的记录没有通过。请帮我找到解决方案或提供问题的替代方案。
--Controller code
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AssignLibrarian(FormCollection FC, string command)
{
foreach (string key in FC.AllKeys)
{
// Process Id Key values
if (key == "item.Id")
{
string IdValues = FC[key];
string[] PartIdArray = IdValues.Split(',');
foreach (string str in PartIdArray)
PartIdDictionary.Add(i++, str);
}
if (key == "item.IsSelected")
{
string SelectedIdValues = FC[key];
string[] PartSelectedIdArray = SelectedIdValues.Split(',');
for (int PartId = 0; PartId < PartSelectedIdArray.Length; PartId++)
{
if (PartSelectedIdArray[PartId] == "true")
{
PartSelectedIdDictionary.Add(j++, PartSelectedIdArray[PartId]);
PartId++;
}
else
PartSelectedIdDictionary.Add(j++, PartSelectedIdArray[PartId]);
}
}
}
}
查看
@model IEnumerable<DFM.CMS.Model.PartRequest>
@foreach (var item in Model)
{
<tr>
<td style="width: 30px; word-wrap: break-word">
@Html.DisplayFor(model => item.CPN)
@Html.HiddenFor(model => item.Id)
</td>
<td style="width: 50px; word-wrap: break-word">
@Html.DisplayFor(modelItem => item.Manufacturer)
</td>
<td style="width: 50px; word-wrap: break-word">
@Html.DisplayFor(modelItem => item.MPN)
</td>
<td style="width: 70px; word-wrap: break-word">
@Html.DisplayFor(modelItem => item.VPLManufacturer)
</td>
<td style="width: 100px; word-wrap: break-word">
@* @Html.DisplayFor(modelItem => item.PartDescription)*@
@if (item.PartDescription != "" & item.PartDescription != null)
{
if (item.PartDescription.Length > 50)
{
@:@Html.LabelFor(modelItem => item.PartDescription, (item.PartDescription.Substring(0, 50) + "..."), new { title = item.PartDescription})
}
else
{
@:@Html.LabelFor(modelItem => item.PartDescription, item.PartDescription, new { title = item.PartDescription})
}
}
else
{
@:@Html.DisplayFor(modelItem => item.PartDescription, new { title = item.PartDescription})
}
</td>
<td style="width: 50px; word-wrap: break-word">
@Html.DisplayFor(modelItem => item.VPLPackage)
</td>
<td style="width: 50px; text-align: center">
@Html.DisplayFor(modelItem => item.RefDesQuantity)
</td>
<td style="width: 40px; word-wrap: break-word">
@Html.DisplayFor(modelItem => item.Librarian.Name)
</td>
<td style="width: 35px; word-wrap: break-word">
@Html.DisplayFor(modelItem => item.Status)
</td>
<td style="width: 85px">
@if (item.Status == DFM.CMS.Model.PartRequestStatus.Completed)
{
@Html.TextAreaFor(modelItem => item.Comments, new { rows = 3, cols = 1, disabled = "disabled" })
}
else
{
@Html.TextAreaFor(modelItem => item.Comments, new { rows = 3, cols = 1 })
}
</td>
<td style="width: 30px; text-align: center">
@if (item.Status == DFM.CMS.Model.PartRequestStatus.Completed)
{
@Html.CheckBoxFor(modelItem => item.IsSelected, new { disabled = "disabled" })
}
else
{
@Html.CheckBoxFor(modelItem => item.IsSelected,new {@class = "SubCheckBox" })
}
</td>
</tr>
}