asp.net MVC 4 Telerik Grid Ajax issue

て烟熏妆下的殇ゞ 提交于 2019-12-11 07:37:51

问题


i am facing an issue with mvc telerik grid there is my view :

@(Html.Telerik().Grid(Model.EmployeeList)
.Name("EmployeeGrid")
.Columns(colums =>
    {
        colums.Bound(e => e.First_Name);
        colums.Bound(e => e.Last_Name);
        colums.Bound(e => e.Hire_Date);
        colums.Bound(e => e.Home_Phone);
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding", "Home"))
    .Groupable()
    .Sortable()
    .Pageable(paging=>paging.PageSize(10))
    .Filterable()
    )

and there is my controller code

[AcceptVerbs(HttpVerbs.Post)]
    [GridAction]
    public ActionResult _AjaxBinding(GridCommand command)
    {
        using (var contax=new NorthwindEntities()){
            int pagesize=command.PageSize;
            int page=command.Page;

            var EmployeeList = (from items in contax.Employees
                                select new
                                {
                                    items.First_Name,
                                    items.Last_Name,
                                    items.Hire_Date,
                                    items.Home_Phone
                                });
            return View(new GridModel
            {
                Data = EmployeeList
            });
        }
    }

on load the data is loaded correctly from database but internal server error 500 occur when i click on paging or sort data.

thanks in advance.


回答1:


you are using a Linq query inside a disposable scope.but the query execution is deferred until using it (when you have left using {} scope). and you'r context is disposed! solution :

add .ToList at the end of query :

var EmployeeList = (from items in contax.Employees
                                select new
                                {
                                    items.First_Name,
                                    items.Last_Name,
                                    items.Hire_Date,
                                    items.Home_Phone
                                }).ToList();


来源:https://stackoverflow.com/questions/13966078/asp-net-mvc-4-telerik-grid-ajax-issue

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