【问题标题】:How to sort partial view telerik grid?如何对部分视图 Telerik 网格进行排序?
【发布时间】:2013-09-16 01:25:13
【问题描述】:

我在 mvc C# 中使用 Telerik 网格。

我在局部视图中创建了 Telerik 网格。我的 Telerik 网格分类不起作用。

这是我的控制器

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()
    ) 

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

【问题讨论】:

  • 为什么不直接联系 Telerik 支持?

标签: c# asp.net-mvc telerik


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 2013-04-22
    相关资源
    最近更新 更多