Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using Asp.net MVC model binding to postback a list of tasks in a table that gets updated if the checkbox is checked. It works fine on the first page but not on the second page. On the second page the postback has an empty list of ids even though they display on the page. After researching the DataTables website, this is a common issue for events attached to the table and they suggest attaching the events to the table elements before calling the dataTable() method.

I'm not attaching any events to the table, I'm just using the built in Model binding to pass the data back to the controller.

Can anyone tell me how to get this to work?

                <tbody>

                    @for (int i = 0; i < Model.cvsTaskList.Count; i++)
                    {
                        EnterpriseCustomerService.Domain.Infrastructure.cvsTaskModel x = Model.FcvsTaskList[i];

                        <tr>

                            <td align="center">@Html.CheckBoxFor(z => z.cvsTaskList[i].changeAssignedUserID, new { @class = "cb-element" })</td>
                            <td>@x.CVSID </td>
                            <td>@x.TaskID</td>@Html.Hidden("cvsTaskList[" + i + "].TaskID", x.TaskID)
                            <td>@x.ShortDescription</td>
                            @*<td>@x.Description</td>*@
                            <td>@x.SectionCd</td>
                            <td>@x.TaskType</td>
                            <td>@x.assignedPSUser</td>
                            <td>@x.assignUserID</td>
                        </tr>
                    }
                </tbody>
...

 <input type="submit" value="Reassign Selected Task" />

    $(document).ready(function () {
        "use strict";
        $('.check:button').toggle(function () {
            $('input:checkbox').attr('checked', 'checked');
            $(this).val('uncheck all');
        }, function () {
            $('input:checkbox').removeAttr('checked');
            $(this).val('check all');
        });



        /* Initialise the DataTable */
        var oTable = $('#example').dataTable({
            "aoColumns": [
                { "sWidth": "10%" },
                { "sWidth": "10%" },
                { "sWidth": "10%" },
                { "sWidth": "10%" },
                { "sWidth": "10%" },
                { "sWidth": "10%" },
                { "sWidth": "10%" },
                { "sWidth": "10%" }
            ],
            "oLanguage": {
                "sSearch": "Search all columns:"
            },
            "bAutoWidth": false
        });


        /* Add a select menu for each TH element in the table footer */
        $("tr td.filter").each(function (i) {
            if (i > 0) {
                this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(i));
                $('select', this).change(function () {
                    oTable.fnFilter($(this).val(), i);
                });
            }
        });

    });

controller method

        [HttpPost]
        public virtual ActionResult UpdateTask(ManageTaskModel model)
        {
            if (model.newUser != null)
            {
                var tasksToUpdate = new List<Int64>();
                foreach (var task in model.cvsTaskList) // this is empty on second page postback
                {
                    if (task.changeAssignedUserID == true) { tasksToUpdate.Add(task.TaskID); }

                }

                // new method that tasks newUser and tasksToUpdate as params and updates the task
                Orchestrator.UpdateTasksNewUser(model.newUser,tasksToUpdate);



            }
            return this.RedirectToAction("ManageTasks");

        }
share|improve this question
1  
I have the same issue today. found a way around it. stackoverflow.com/questions/25017597/… –  Adam Bielecki Jul 29 '14 at 16:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.