如何对局部视图telerik网格进行排序?

时间:2013-09-16 01:25:13

标签: c# asp.net-mvc telerik

我使用带有mvc C#的telerik网格。

我在局部视图中创建了telerik网格。我的telerik网格sortiong无效。

这是我的控制器

public ActionResult Index()
{
    var query = from c in db.tblCompanies
                select c;
    return View(query.ToList());
}

public ActionResult SearchCompany(string CompanyName)
{
    var query = from c in db.tblCompanies
                select c;
    if (CompanyName != "")
    {
        query = query.Where(s => s.CompanyName.Contains(CompanyName));
    }

    return PartialView("_comList", query);
}

这是我的观点

script type="text/javascript">

    function SearchCompany() {
        var CompanyName = document.getElementById('txtCompanyName').value;
        $.ajax({

            type: 'POST',
            dataType: 'html',
            url: '@Url.Action("SearchCompany", "Company")',
            data: ({ CompanyName: CompanyName }),
            success: function (data) {
                //alert(data);
                $('#CompList').html(data);

            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
            }
        });
    }
</script>

<table>
  <tr>
    <td>Company Name:</td>
    <td>@Html.TextBox("txtCompanyName")</td>
  </tr>
  <tr>
    <td></td>
    <td><input type="button" value="Search" onclick="SearchCompany();" /></td>
  </tr>
</table>      

<div id="CompList">
  @Html.Partial("_comList", CompanyList)
</div>

这是我的部分观点

@(Html.Telerik().Grid(Model)
        .Name("CompanyGrid")


        .Columns(columns =>
        {
            columns.Bound(o => o.CompanyId).Width(5).Title("ID"); ;
            columns.Bound(o => o.CompanyName).Width(50);
            columns.Bound(o => o.CompanyAddress).Width(60).Title("Address");           
            columns.Bound(o => o.Phone).Width(20);
            columns.Bound(x => x.PKComID)
          .Width(30)
              .Template(x => Html.ActionLink("Edit", "Edit", new { id = x.PKComID }))
           .ClientTemplate("<a href=\"Edit/<#= Id #>\"> EDIT </a>")
           .Title("Edit").Sortable(false);

            columns.Bound(x => x.PKComID)
        .Width(30)
            .Template(x => Html.ActionLink("Delete", "Delete", new { id = x.PKComID }, new { onclick = "return confirm('Are you sure you wish to delete this Company?');" }))
         .ClientTemplate("<a href=\"Edit/<#= Id #>\"> EDIT </a>")
         .Title("Delete").Sortable(false);

        })

          .Pageable(paging => paging.PageSize(15).Style(GridPagerStyles.NextPreviousAndNumeric).Position(GridPagerPosition.Bottom))
                 .Sortable()
    ) 

我的代码有什么问题..排序不起作用 请帮帮我。

1 个答案:

答案 0 :(得分:0)

确保您已正确实施Telerik ASP.NET MVC - Grid - Sorting演示中的所有步骤。