ASP .NET MVC 中的 jQuery 网格绑定非常慢
我在 ASP 中使用 Infragistics jQuery 网格 .NET MVC 应用程序。我的数据源是引用 SQL 数据库的 ADO .NET 实体模型。这是我的控制器中用于设置网格并提供数据源的代码:
public ActionResult Index()
{
var model = new GridModel();
model.DataSourceUrl = Url.Action("GetInstrumentListData");
this.InitializeGridOptions(model);
return View(model);
}
public JsonResult GetInstrumentListData()
{
var model = new GridModel();
this.InitializeGridOptions(model);
model.DataSource = _db.InstrumentLists.OrderBy(x => x.Tag).AsQueryable<InstrumentList>();
return model.GetData();
}
private void InitializeGridOptions(GridModel model)
{
Code to create columns...
model.DefaultColumnWidth = "100px";
model.Width = "100%";
model.Height = "700px";
model.Features.Add(new GridFiltering());
var sort = new GridSorting();
sort.Mode = SortingMode.Multiple;
model.Features.Add(sort);
var paging = new GridPaging();
paging.PageSize = 30;
model.Features.Add(paging);
var selection = new GridSelection();
selection.Mode = SelectionMode.Row;
selection.MultipleSelection = true;
model.Features.Add(selection);
}
网格需要很长时间才能显示(25-40 秒),所以我做了一些调查,它是 model.GetData( )
调用 GetInstrumentListData()
一直占用时间。根据 Intellisense,该函数首先执行数据绑定并生成 JsonResult 对象。
我想,也许因为我试图显示总共 1000 条记录(即使启用了分页并且每个视图只显示 30 条),可能需要一段时间才能将这些记录转换为 JSON,所以我将记录数量减少到10(从 1.2mb JSON 数据到 12.5kb)。时间上没有区别。
这是来自 Firebug 的请求跟踪。
对正在发生的事情有什么想法吗?
编辑: @allentranks 的回答和 @AlastairPitts 的评论让我意识到这实际上是我获取数据的来源。源不是表而是视图,它是由我的 DBA 通过一大堆疯狂的连接创建的。事实证明,运行查询需要 13 秒以上的时间,因此加载需要这么长时间也就不足为奇了。感谢您的帮助。
I am using the Infragistics jQuery grid in my ASP .NET MVC application. My datasource is an ADO .NET Entity model referencing an SQL database. Here is the code from my controller to set up the grid and provide the datasource for it to pull from:
public ActionResult Index()
{
var model = new GridModel();
model.DataSourceUrl = Url.Action("GetInstrumentListData");
this.InitializeGridOptions(model);
return View(model);
}
public JsonResult GetInstrumentListData()
{
var model = new GridModel();
this.InitializeGridOptions(model);
model.DataSource = _db.InstrumentLists.OrderBy(x => x.Tag).AsQueryable<InstrumentList>();
return model.GetData();
}
private void InitializeGridOptions(GridModel model)
{
Code to create columns...
model.DefaultColumnWidth = "100px";
model.Width = "100%";
model.Height = "700px";
model.Features.Add(new GridFiltering());
var sort = new GridSorting();
sort.Mode = SortingMode.Multiple;
model.Features.Add(sort);
var paging = new GridPaging();
paging.PageSize = 30;
model.Features.Add(paging);
var selection = new GridSelection();
selection.Mode = SelectionMode.Row;
selection.MultipleSelection = true;
model.Features.Add(selection);
}
The grid was taking ages to display (25-40 secs) so I did some investigating and it's the model.GetData()
call in GetInstrumentListData()
that is taking up all the time. According to Intellisense, this function first performs data binding and generates the JsonResult object.
I thought that maybe since I was attempting to display a total of 1000 records (even though pagination is enabled and only displaying 30 each view) that maybe it was taking a while to convert those records into JSON, so I reduced the amount of records to 10 (from 1.2mb of JSON data to 12.5kb). There was no difference in time.
Here is the request tracing from Firebug.
Any ideas on what is happening?
EDIT: @allentranks' answer and @AlastairPitts comment made me realise that it is in fact the source I am getting my data from. The source isn't a table but a view, which was created by my DBA from a whole bunch of crazy joins. Turns out that it takes 13+ secs to run the query, so its no wonder its taking so long to load. Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定为什么您的 InstrumentLists 需要在查询中订购两次。
这应该可行:
并且,您可能需要在 Tag 列上创建索引以更快地执行查询。
I am not sure why your InstrumentLists need to be ordered twice in your query.
this should work:
And, you maybe need to create an index on the Tag column to execute the query more quickly.
从控制器返回的数据有问题(数据量太多。10 条记录需要 12.5kb!)。您应该在 firebug 中检查从服务器返回的 json 数据。确保您仅接收特定于网格所需的数据。我建议为网格制作一个自定义视图模型。
作为旁注,我想分享一下,对于每页 50 条记录和 11 列的网格,我收到的 json 数据为 1.9 kb 和 967 字节。
There is something wrong with data that you are returning from controller (amount of data is too much. 12.5kb for 10 records!). you should inspect json data returned from the server in firebug. Make sure that you are only receiving data that is required and specific to the grid. i would suggest making a custom view model for the grid.
As a side note i would like to share that for a grid with 50 records per page and 11 columns the json data i receive is 1.9 kb and its 967 bytes.