Q:

Add items to a list with checkbox

I am trying to use checkboxes for a prepopulated list to preform an action if the item's checkbox is checked.
In my model I have a list that uses the GET function to populate every property except for the AddThis boolean:
Public Property TaskList As List(Of TaskItem)
 Get
  Return (From a In db.Web.Backlogs
          Join b In db.Web.References On a.StatusID Equals b.RefID
          Where a.RelateSprint Is Nothing And b.Name <> "Resolved" And b.Name <> "Closed"
          Select New TaskItem With {
           .ItemID = a.ItemID,
           .ItemName = a.ItemName,
           .RelateItem = If(a.RelateItem IsNot Nothing, a.RelateItem, 0),
           .OwnerID = If(a.UserIDOwn IsNot Nothing, a.UserIDOwn, 0),
           .TypeID = If(a.TypeID IsNot Nothing, a.TypeID, 0),
           .Type = If(db.Web.Backlogs.Count(Function(t) t.RelateItem = a.ItemID) > 0, "Epic", If(a.TypeID <> db.Web.References.FirstOrDefault(Function(t) t.Name = "Bug" And t.RefTypeID = 14).RefID, "User Story", "Bug")),
           .Priority = If(a.Priority = 1, "Low", If(a.Priority = 2, "Medium", If(a.Priority = 3, "High", If(a.Priority = 4, "Critical", String.Empty)))),
           .KanBan = a.KanBan,
           .WorkUnit = a.WorkUnit}).ToList
  End Get
  Set(value As List(Of TaskItem))
  End Set
End Property
Public Class TaskItem
 Public Property AddThis As Boolean
 Public Property ItemID As Integer
 Public Property ItemName As String
 Public Property RelateItem As Integer
 Public Property OwnerID As Integer
 Public Property TypeID As Integer
 Public Property Type As String
 Public Property Priority As String
 Public Property KanBan As Integer
 Public Property WorkUnit As Integer
End Class

In my view I add a checkbox for the AddThis Boolean for each item in the list using @Html.CheckBoxFor(Function(m) i.AddThis, New With {.class = "ttip", .title = "Add This to the Sprint."})
Then in my post controller I have this:
For Each i In model.TaskList
 If i.AddThis = True Then
  Dim Backlog As New Backlog
  Backlog = db.Web.Backlogs.Find(i.ItemID)
  Backlog.RelateSprint = SprintID
  Backlog.KanBan = 1
  Backlog.DateDue = Sprint.DateDue
  Backlog.DateUpdated = Now
  Try
   db.Web.Entry(Backlog).State = EntityState.Modified
   db.Web.SaveChanges()
   Allgood = True
  Catch ex As Exception
   ModelState.AddModelError("", "Unable to save Sprint. Please Try Again")
   Allgood = False
  End Try
 End If
Next

I have also tried For Each i In model.TaskList.Where(Function(m) m.AddThis = True)
But when I check boxes and click submit it doesn't acknowledge that any of the AddThis booleans are true. Can anyone let me know how I can do this correctly?

A:

First of all you haven't posted the entire view and the controller action methods, which are used in this scenario. So I am making some assumptions over here. 
As @Alan said this seems to be a problem of how the names of the controls are generated.
This is just a sample that I quickly created.
Following is a simple model similar to what you have created.
public class ModelToSubmit
{
    public List<TaskItem> TaskList { get; set; }
}
public class TaskItem
{
    public bool Addthis { get; set; }
    public string SomeProperty { get; set; }
}

Following is how the controller action methods look.
[HttpPost]
public ActionResult Index1(ModelToSubmit taskItems)
{
    foreach (var item in taskItems.Tasks)
    {
        if (item.Addthis)
        {

        }
    }
    return Json("Index Success", JsonRequestBehavior.AllowGet);
}

[HttpGet]
public ActionResult Index()
{
    var tasks = new List<TaskItem> 
    { 
        new TaskItem{ SomeProperty = "Line1"},
        new TaskItem{ SomeProperty = "Line2"},
        new TaskItem{ SomeProperty = "Line3"},
        new TaskItem{ SomeProperty = "Line4"},
        new TaskItem{ SomeProperty = "Line5"},
    };
    var mod = new ModelToSubmit();
    mod.TaskList = tasks; 
    return View(mod);
}

Following is the view.
@model MVC3Stack.Models.ModelToSubmit
@{
    ViewBag.Title = "Create";
}
@using (Html.BeginForm("Index1", "Home", FormMethod.Post))
{
    <table>
        @for (int i = 0; i < Model.TaskList.Count; i++)
        {
            <tr>
                <td>
                    @Html.TextBoxFor(m => Model.TaskList[i].SomeProperty)
                </td>
                <td>
                    @Html.CheckBoxFor(m => Model.TaskList[i].Addthis)
                </td>
            </tr>
        }
    </table> 
    <input type="submit" value="Post" />
}

With this model and view a list of textboxes and checkboxes in a table as shown in following snapshot.

when I click on the post button I get the entire TaskList model filled with the taskItems
here is the snapshot of the quickwatch window when I select first two items and post.
the code is in c# but you can easily convert it to vb.net.

Hope this works for you.

