Hi all, i'm using mvc and jquery datatables, with serve side processing.
I have created two Class Model:
the first jQueryParamModel, to pass dataTables parameters to action controller
the second rapresent two custom search criteria
After i have created a strongly typed view with Home2Model, named index.cshtml
I'have create a contoller action that recive in input this parameters:
JQueryDataTableParamModel bind work properly, but hm param isn't valorized (null). the mvc binding doesn't work correctly.
Can any one help me ?
Thank you in advantage.
I have created two Class Model:
the first jQueryParamModel, to pass dataTables parameters to action controller
public class JQueryDataTableParamModel { /// <summary> /// Request sequence number sent by DataTable, same value must be returned in response /// </summary> public string sEcho{ get; set; } /// <summary> /// Text used for filtering /// </summary> public string sSearch{ get; set; } /// <summary> /// Number of records that should be shown in table /// </summary> public int iDisplayLength{ get; set; } /// <summary> /// First record that should be shown(used for paging) /// </summary> public int iDisplayStart{ get; set; } /// <summary> /// Number of columns in table /// </summary> public int iColumns{ get; set; } /// <summary> /// Number of columns that are used in sorting /// </summary> public int iSortingCols{ get; set; } /// <summary> /// Comma separated list of column names /// </summary> public string sColumns{ get; set; } }
the second rapresent two custom search criteria
public class Home2Model { public CriteriaModel SearchCriteria1 { get; set; } public CriteriaModel SearchCriteria2 { get; set; } } public class CriteriaModel { public int? integer { get; set; } }
After i have created a strongly typed view with Home2Model, named index.cshtml
@model GenericSearch.UI.Models.Home2Model <link href="@Url.Content("~/Content/dataTables/demo_table.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/jquery.dataTables.min.js")" type="text/javascript"></script> <script> $(document).ready(function () { var oTable = $('#myDataTable').dataTable({ "bServerSide": true, "sAjaxSource": "/Home2/AjaxHandler", "bProcessing": false, "sServerMethod": "POST", "fnServerData": function (sSource, aoData, fnCallback) { aoData.push({ "name": "hm", "value": $("myForm").serialize() }); $.ajax({ "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback }) } }); }); </script> <h1>Search</h1> <br /> @using (Html.BeginForm("Index", "Home2", FormMethod.Post, new { id="myForm"})) { <div > @Html.EditorFor(m => m.SearchCriteria1) @Html.EditorFor(m => m.SearchCriteria2) <br /> <input type="submit" name="default" value="Filter" /> <br /><br /> <table id="myDataTable" class="display"> <thead> <tr> <th>a</th> <th>b</th> <th>c</th> <th>d</th> <th>e</th> <th>f</th> </tr> </thead> <tbody> </tbody> </table> </div> }
I'have create a contoller action that recive in input this parameters:
[HttpPost] public ActionResult AjaxHandler(JQueryDataTableParamModel param,Home2Model hm) { return new EmptyResult(); }
JQueryDataTableParamModel bind work properly, but hm param isn't valorized (null). the mvc binding doesn't work correctly.
Can any one help me ?
Thank you in advantage.