sortable telerik grid + NHibernate, IQueryable and ASP.NET MVC

懵懂的女人 提交于 2019-12-01 12:00:22

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!