I am building a tool to add contacts to distribution lists and one contact can be in multiple distribution lists. I am using a List Group with checkboxes for users to display and select the distribution lists. On the edit contact page I need to check the checkboxes in the list group of the distribution lists that the contact is already a member of. I simply cannot work out how to do this. I am using asp.net core with page models (no controllers) and razor pages
This on my cshtml page:
<label for="DistributionListSelectIDLG" id="SeletDistributionListLabel" class="control-label">Select a Distribution List</label>
<div class="overflow-auto" style="max-height:500px">
<ul class="list-group" id="DistributionListSelectIDLG" role="group" aria-labelledby="SeletDistributionListLabel">
@foreach (var item in Model.CreateContactViewModel.DistributionLists)
{
<li class="list-group-item"><input type="checkbox" name="DistributionListSelectID" id="@item.DistributionListId" value="@item.DistributionListId" aria-label="@item.ListName" /> @item.ListName</li>
}
</ul>
</div>
This is on my code behind page
Contact = await _context.Contacts.FirstOrDefaultAsync(m => m.ContactId == id);
if (Contact == null)
{
return NotFound();
}
CreateContactViewModel = new ContactViewModel()
{
DistributionLists = _distService.GetAllLists().Where(d => d.IsDeleted == false).OrderBy(d => d.ListName).ToList(),
ListsAndContacts = _linkService.GetListsForContact((int)id).ToList()
};
foreach (var dlitem in CreateContactViewModel.ListsAndContacts)
{
// Do something here to populate the checkboxes
}
return Page();
There are two interfaces, one to get the full list of DLs, and one to get a list of DLs that contact belongs to.
Thanks
