This is a migrated thread and some comments may be shown as answers.

Nhibernate 3 with ajaxfied Grid

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Konrad
Top achievements
Rank 1
Konrad asked on 02 Mar 2011, 11:54 AM
Is it possible to use nhibenrate with ajaxfied grid? When I try to bind data i get error message

Incorrect syntax near 'Index'. If this is intended as a part of a table hint, 
A WITH keyword
and parenthesis are now required. See SQL Server Books Online for proper syntax.
My Grid:
@(Html.Telerik().Grid<Product>()
    .Name("Grid")
    .DataBinding(dataBinding => dataBinding.Ajax().Select("_GetProducts", "Home"))
    .Columns(c =>
    {
         c.Bound(o => o.Name).Title("name");
    })
    .Groupable()
    .Sortable()
    .Pageable()
    .Filterable()
My repository method:
public IList<Product> GetProducts()
{
 
   return _session.Query<Product>().Where(x => x.Status == "A").ToList<Product>();
 
}

1 Answer, 1 is accepted

Sort by
0
Andy
Top achievements
Rank 1
Veteran
answered on 11 Mar 2011, 04:22 AM
I've managed to get NHib3.0 working with Grid using Ajax calls.   The DataBinding.Ajax().Select("_GetProducts", "Home") instructs the grid to call HomeController._GetProducts()    _GetProducts should have the [GridMethod] attribute applied to it and return the GridModel( Repository._GetProducts() as IQueryable).  

I'm using these two methods in my controller - Index is the first view, subsequent Ajax callbacks use AjaxSelect.

public ActionResult Index()
{
    var myClients = from c in _repository.Queryable
select new ClientViewModel
            {
                Id = c.Id,
                ClientName = c.ClientName,
                Comments = c.Comments,
                WebPage = c.Web
            };
    return View(myClients);
}
  
[GridAction]
public ActionResult AjaxSelect()
{
    return View(new GridMode<ClientViewModel>
    {
        Data = from c in  _repository.Queryable
                select new ClientViewModel
                { 
                    Id = c.Id, 
                    ClientName = c.ClientName, 
                    Comments = c.Comments, 
                    WebPage = c.Web 
                }
     });
}

 


Andy
Tags
Grid
Asked by
Konrad
Top achievements
Rank 1
Answers by
Andy
Top achievements
Rank 1
Veteran
Share this question
or