Implementing Search criteria using MVC return no record

2 posts, 1 answers
  1. David
    David  avatar
    20 posts
    Member since:
    Oct 2012

    Posted 15 Apr 2013 Link to this post

    I am trying to implement search criteria which bind to Kendo Ui grid.
    However it return no record and no error display. Is there something i

    Controller code :

    public ActionResult SearchProduct(ProductSearchCriteria criteria)
    string nameCriteria = string.Empty;
    string descCriteria = string.Empty;

    TTSEntities dc = new TTSEntities();
    if (!string.IsNullOrWhiteSpace(criteria.Name)) nameCriteria = criteria.Name.ToLower().Trim();

    if (!string.IsNullOrWhiteSpace(criteria.Community)) descCriteria = criteria.Desc.ToLower().Trim();

    var results = dc.Products.AsQueryable();
    if (criteria.Name!= null)
    results = results.Where(b => b.Name== criteria.Name);

    if (criteria.Desc!= null)
    results = results.Where(b => b.Desc== criteria.Desc);

    return PartialView("_ProductGrid", results.ToList());


    @model HHIMS_Web_App.Models.ProductSearchCriteria

    @using (Html.BeginForm())
    <div id="headerpanel">
    <legend style="font-size:14px">Search Criteria</legend>
    <div class="editor-label">
    @Html.LabelFor(model => model.Name)

    <div class="editor-field">
    @Html.EditorFor(model => model.Name)

    <div class="editor-label">
    @Html.LabelFor(model => model.Desc)


    <div class="editor-field">
    @Html.EditorFor(model => model.Desc)

    <div class="smallBox">

    <input type="button" value="Search" id="btnProductSearch" style="height:33px; font-size:14px; background-color:#3399FF" class="k-button" />



    <script type="text/javascript">

    $(document).ready(function () {

    $('#btnProductSearch').click(function (e) {
    var searchParameters = GetSearchParameters();
    var jsonData = JSON.stringify(searchParameters, null, 2);

    url: '@Url.Content("~/ProductDetails/SearchProduct/")',
    type: 'POST',
    data: jsonData,
    datatype: 'html',
    contentType: 'application/json; charset=utf-8',
    success: function (data) {
    error: function (request, status, err) {


    function GetSearchParameters() {
    var hrn = $("#Name").val();
    var community = $("#Desc").val();

    return { Name: name,
    Desc: desc





    <fieldset class="searchResults">
    <legend style="font-size:14px">Search Result</legend>
    <br />

    .HtmlAttributes(new { @Style = "align:center; font-size:10px; width:500px" })
    .Columns(columns =>

    columns.Bound(p => p.Name);
    columns.Bound(p => p.Desc);

    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable(paging => paging

    .PageSizes(new int[] { 5, 10, 25, 50 })

    .ColumnMenu(c => c.Columns(false))
    .DataSource(dataSource => dataSource
    .Ajax()//bind with Ajax instead server bind
    .Model(model =>
    model.Id(p => p.Name);



  2. Answer
    Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 17 Apr 2013 Link to this post

    Hello David,

    Basically to filter the Grid you should either use the filter method of the dataSource or the read method and pass additional parameters (your search criteria).

    Based on the parameters send to the server you should return different number of records.

    Or you can perform your own $.ajax request and return collection from the server which you can pass to the data method of the dataSource.

    Kind regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top