mardi 14 juillet 2015

MVC3 model is null if Datatable filtering is applied

I'm using the jQuery Datatable (http://ift.tt/1gQlUua) for styling, sorting and filtering of list of data.

My razor is like [ which list a set of items and allow user to edit name and aim to save all changes to Db on single GO]

@using (Html.BeginForm()) {
    <div>
        <fieldset>
            <legend>Modify items</legend>
            <p>
                <input type="submit" value="Save" />
            </p>
        <table cellpadding="0" cellspacing="0" border="0" class="" id="SelectEmpTable"> 
            <thead>
                <tr>
                    <th>Old Name</th>
                    <th>New Name</th>
                </tr>
            </thead>
            <tbody>
            @for (int i = 0; i < @Model.Count();  i++)
            {
            <tr>
                <td class="editor-label">
                    @Html.DisplayForm(m => m[i].Name)                       
                    @Html.HiddenFor(m => m[i].Id)
                </td>
                <td>
                     @Html.TextBoxFor(m => m[i].Name) //allow user to edit
                </td>
            </tr>
            }
            </tbody>
        </table>
        </fieldset>
    </div>
}

and then use the jQuery plugin for the rest...

$(document).ready(function() { 
     $('#SelectEmpTable').dataTable(); 
} );

When posting back without filtering the table (on the client side) my model is populated.

    [HttpPost]
    public ActionResult SubmissionForm(IList<CompanyModel> model)
    {
        //model is not null and has all list of values
    }

However when filtering the table, and then submit form , the model is then null, in the above code.

How can i make sure both filtering is possible and get data in model while submitting form

Aucun commentaire:

Enregistrer un commentaire