MVC中foreach循环内的HTML表格执行速度太慢 [英] HTML table inside foreach loop in MVC is performing too slow

查看:71
本文介绍了MVC中foreach循环内的HTML表格执行速度太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



当我尝试使用MVC中的foreach循环绑定模型数据时,我能够在2-3中获得十万条记录控制器端的秒数,但是当数据从控制器转到我使用foreach的地方时,性能太慢,大约需要10分钟才能绑定5万条记录。



下面是我的代码示例:

Dear All,

While I am trying to bind the Model data using foreach loop in MVC, I am able to get lakhs of records in just 2-3 seconds at Controller side, but when the data goes from controller to view where I am using foreach, the performance is too slow which takes about more than 10 mins to bind just 50k records.

Below is my code sample :

@foreach (var device1 in Model.FaultyDevices)
{
    <tr>
        <td>
            @Html.DisplayFor(mod => device1.status)
        </td>
        <td>
            @Html.DisplayFor(mod => device1.pointAddress)
        </td>
    </tr>
}



我们非常感谢任何有关html表格中快速绑定的帮助或建议。



问候,


Any help or suggestion on faster binding in html table would be greatly appreciated.

Regards,

推荐答案

创建这么大的表总是很慢。没有人可以处理那么多的信息,因此解决方案是通过使用paging\filtering\sorting等来减少你显示的内容,只显示相关的数据位。
Creating such a large table is always going to be slow. No human being can possibly process that amount of information so the solution is to reduce what you display by using paging\filtering\sorting etc to show only relevant bits of data.


渲染有这么大记录的表总是需要时间。我建议你改用网格。或者为您的表提供分页功能 - 不会一次显示所有数据。



参考这篇文章关于在MVC中使用基本网格 -

在ASP.NET MVC中使用Grid.MVC [ ^ ]

有替代品对于这个网格,你可以谷歌吧:)





-KR
Rendering the table with such large records always going to take time. I'd suggest you to use the Grid instead. Or provide the paging feature for your table - that won't display all the data in one shot.

Refer this article about using the basic grid in MVC-
Using the Grid.MVC in ASP.NET MVC[^]
There are alternatives too for this grid, you can google it out :)


-KR


这篇关于MVC中foreach循环内的HTML表格执行速度太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆