简体   繁体   English

asp.net MVC 4 Telerik Grid Ajax问题

[英]asp.net MVC 4 Telerik Grid Ajax issue

i am facing an issue with mvc telerik grid there is my view : 我正面临mvc telerik网格的问题,有我的观点:

@(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. 在加载时,数据从数据库正确加载,但当我点击分页或排序数据时,会发生内部服务器错误500。

thanks in advance. 提前致谢。

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). 您正在一次性范围内使用Linq查询。但是查询执行将推迟到使用它时(当您using {}范围时)。 and you'r context is disposed! 并且你的背景被处理掉! solution : 方案:

add .ToList at the end of query : 在查询结尾添加.ToList

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM