Question

I took over another project and have fixed everything else except this one problem. I think I've seen this before, but can't for the life of me remember what the solution was.

The table in the .spark view looks like this. Then a JQuery script, using getJSON() is called to first clear all of the rows and then populate the tbody, building out all of the rows and columns and adding a checkbox in the first column for each row - each checkbox is called 'testitem'.

<form id='new_test_items' name='new_test_items' method='post' action='${Url.Action("AddTestItems", new { id = Model.TestID })}'>
    <table id='component_list' name='component_list' class='component_list_table striped_table' cellpadding='0' border='0' cellspacing='0'>
        <thead>
            <tr>
                <th>&nbsp;</th>
                <th>Column1</th>
                <th>Column2</th>
                <th>Column3</th>
                <th>Column4</th>
                <th>Column5</th>
                <th>Column6</th>
                <th>Column7</th>
                <th>Column8</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</form>

There's also a .click event handler to submit the form:

$('#add_selected').click(function() {

    var $items = $('#component_list input:checkbox:checked');

    // If none checked, alert
    if ($items.length == 0) {
        alert('No items have been selected.');
        return false;
    }
    else {
        $('#new_test_items').submit();
    }
});

The form is submitted to the controller action and I assumed that the checkboxes would have been passed back in the form collection.

    public ActionResult AddTestItems(int id, FormCollection coll)
    {
        Dictionary<string, ValueProviderResult> vals = coll.ToValueProvider() as Dictionary<string, ValueProviderResult>;

        // vals is null here
    }

When vals is created, it's returned as null. So either the formcollection contains no data or there's an issue creating the dictionary that I'm not aware of.

Any help would be greatly appreciated.

Thanks!

Was it helpful?

Solution

Checkboxes are only submitted as HTTP POST data when they are checked. Have you tried checking a couple of the boxes, and then seeing if they appear in the form collection?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top