I'm kind of new to MVC and I need help figuring this issue out:

I have this method on a controller:

[HttpPost]
        public List<BillingModel> DeleteFOP(List<BillingModel> FOPList)
        {
            /*If FOPList is null we instantiate it to a type of BillingModel List
            Effectively avoiding an exception to occur*/
            if (FOPList == null)
            {
                FOPList = new List<BillingModel>();
            }
            else
            {   //remove indexed(FOP) item if the checkbox is checked.
                for (int i = FOPList.Count - 1; i >= 0; i--)
                {
                    if (FOPList[i].CheckBox == true)
                    {
                        FOPList.RemoveAt(i);
                    }
                }
            }

           return FOPList;
        }

Which is triggered after they click on a Delete submit button

and stepping through the iteration and index the item removed and item remaining seem correct, this populates the < td >s in the View

@for (int i = 0; i < Model.editBillingFOPList.Count;i++ )
                        { 
                        <tr>
                           <td>@Html.TextBox("FOPList[" + @i + "].Fund", 
                                                Model.editBillingFOPList[i].Fund)</td>
                            <td>@Html.TextBox("FOPList[" + @i + "].ORGN", 
                                                Model.editBillingFOPList[i].ORGN)</td>
                            <td>@Html.TextBox("FOPList[" + @i + "].Program", 
                                                Model.editBillingFOPList[i].Program)</td>
                            <td>@Html.TextBox("FOPList[" + @i + "].Percentage", 
                                                Model.editBillingFOPList[i].Percentage)</td>
                            <td>@Html.CheckBox("FOPList[" + @i + "].CheckBox", 
                                                Model.editBillingFOPList[i].CheckBox, new { @checked = false })</td>
                        </tr>
                        } 

and stepping through this still displays the right item marked for deletion, e.g.:

item 1: Field1 Field2 Field3 Field4 1 √

item 2: Field1 Field2 Field3 Field4 2

Item 2 should remain when my view is rendered and after debugging it seems as though Item 2 will be displayed but then the view renders and the item remaining is Item 1 , and Item 2 gets deleted- any advise will be greatly appreciated !

Related posts

Recent Viewed