0

I wanted to set up a list with checkboxes on a reminder column to remind people to continue with their application which could be ticked and then returned to the controller to update the source applicants table.

After much searching, I found the answer, create a virtual table which takes the data from the source, send that to the page where those requiring reminders can be ticked, then, on return, put it back into the source. Works fine.

The following is the beginning of the CheckBoxItem model:

public class CheckBoxItem
{
    public int Id { get; set; }

    public DateTime DateRegistered { get; set; }
    public bool SendReminder1 { get; set; }
    public DateTime? Reminder1Sent { get; set; }
}

The applicants are then called from the applicants table:

Applicants = _Repository.GetApplicantsList_Registered_NotCompleted();

and the routine that creates the check box list then created

checkBoxItems = GetCheckBoxItems(Applicants, checkBoxItems);

The beginning of GetCheckBoxItems is:

private List<CheckBoxItem> GetCheckBoxItems(IList<Applicant> Applicants, List<CheckBoxItem> checkBoxItems)
{
    foreach (var applicant in Applicants)
        checkBoxItems.Add(new CheckBoxItem()
                              {
                                  Id = applicant.Id,
                                  DateRegistered = applicant.DateRegistered,
                                  SendReminder1 = blSendReminder1,
                                  Reminder1Sent = applicant.Reminder1Sent,
                              }
}

This is then displayed on the page with a CheckBoxFor and a HiddenFor:

@Html.CheckBoxFor(item => Model[i].SendReminder2)
@Html.HiddenFor(item => Model[i].Id)

The result shows checkboxes with the correct ticked/unticked depending on true/false values (next to the checkboxes is a temporary @Model[i].SendReminder1 to show the actual data). Checkbox with correct display

However I then put a button on the form that calls up a filtered version of the applicants data, filtering out those people that have already been reminded. When the filter is applied by the controller the checkboxes show a tick even though the boolean column SendReminder1 is actually storing false.

Attached is a screenshot of two checkbox showing true when the data is false, the pattern with the first checkbox unticked and the second and third ticked is the same as the full set of unfiltered data:

Checkbox showing true when data is false

I've examined the data being sent and it is false. I then thought that the CheckBoxItems must be remembering the original data even when overwritten, so I added a new list:

checkBoxItems = new List<CheckBoxItem>();

When that didn't solve the problem, I tried:

checkBoxItems.Clear();

Neither of these stops the checkbox from displaying the same pattern of true and false. Any ideas on how I get the CheckBoxItem list to be cleared completely?

7
  • Can you add your full razor/html markup? or at least the loop that displays the table rows Commented Aug 18, 2024 at 15:29
  • By filter, does it refresh the page or do you filter asynchronously via ajax? Commented Aug 18, 2024 at 15:29
  • The filter buttons return to HttpPost in the controller, the filtering is then done and the checkboxitems are returned to the page view. Commented Aug 18, 2024 at 17:58
  • The table row starts: @for (var i=0; i<Model.Count();i++) with the checkbox shown as: @Html.CheckBoxFor(item => Model[i].SendReminder1) @Html.HiddenFor(item => Model[i].Id) Commented Aug 18, 2024 at 18:13
  • I've just thought that if I returned to the controller through HTTPGet, then applied the filters, this may do what I want. Or, use if statements on the web page to show only the relevant records... Commented Aug 18, 2024 at 18:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.