0

我有一个模型,我已经在视图中实现了。数据被传递给控制器​​,我使用控制器中的表单集合检索值。我总共有 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>
    }
4

0 回答 0