我将 Telerik 网格与 mvc C# 一起使用。
我在局部视图中创建了 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()
)
我的代码有什么问题..排序不起作用请帮助我。