asp.net MVC 4 Telerik的电网阿贾克斯问题 [英] asp.net MVC 4 Telerik Grid Ajax issue
本文介绍了asp.net MVC 4 Telerik的电网阿贾克斯问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我面临与MVC Telerik的电网问题
还有就是我的观点:
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()
)
和有我的控制器code
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
});
}
}
在加载数据正确地从数据库中,但内部服务器错误加载当我点击分页或排序的数据发生500
on load the data is loaded correctly from database but internal server error 500 occur when i click on paging or sort data.
在此先感谢。
推荐答案
您正在使用内一次性scope.but查询执行LINQ查询被推迟到使用它(当你离开使用 { }
范围)。
和找你背景布置!
解决方案:
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 :
添加 .ToList
在查询的末尾:
var EmployeeList = (from items in contax.Employees
select new
{
items.First_Name,
items.Last_Name,
items.Hire_Date,
items.Home_Phone
}).ToList();
这篇关于asp.net MVC 4 Telerik的电网阿贾克斯问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文