I am trying to get a telerik grid to work (paging works fine). My view code looks like this:
@(Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.ItemName.Text).Title("Name");
})
.Pageable(pager => pager.PageSize(20))
.Sortable()
)
My controller looks like this:
public ActionResult Index(GridCommand command)
{
return View(BlaRepository.GetBlas(command.PageSize, command.Page));
}
The repository looks like this:
public IQueryable<Bla> GetBlas(int PageSize, int Page)
{
var query = (from e in Session.Query<Bla>() select e).AsQueryable();
return query.Skip((Page - 1) * PageSize).Take(PageSize);
}
I understand that the GridCommand will contain things to be sorted her:
command.SortDescriptors
and I have to marry this up with the repository somehow (or do I ??? as I read somewhere that the telerik engine takes care of this if I use IQueryable).
Unfortunately, I get an exception before the controller is even hit:
Specified method is not supported.
Line 8: @(Html.Telerik().Grid(Model)
I can post the stacktrace if that helps ...
Anyway did someone get this to work using NHibernate, IQueryable and ASP.NET MVC (I am actually using sharp architecture 2.0 RC).
Thanks!
Christian
I just did this yesterday. There is a code sample of this working that Telerik put together which was super useful: http://www.telerik.com/community/code-library/aspnet-mvc/grid/nhibernate-binding.aspx
A couple of things to point out:
- You need to use Nhibernate 3.x. Otherwise filtering won't work
- You don't need to have the paging code, The telerik gridcommand contains that info and plugs it into the IQueryable for you
- This only works with a client side ajax binding, this should look something like:
.DataBinding(dataBinding => dataBinding.Ajax().Select("index", "mycontroller"))
- As you are using ajax binding you won't need to pass the model to the grid, instead you specify the type of model, like so:
.Grid<ItemRowViewModel>()
It worked super well for me in a grid with 400,000 rows. Let me know if you have any trouble setting it up.
来源:https://stackoverflow.com/questions/6764297/sortable-telerik-grid-nhibernate-iqueryable-and-asp-net-mvc