如何在不出现内存异常的情况下在MVC视图上显示大量数据? [英] How do I display huge amount of data on MVC view without getting out of memory exception ?

查看:56
本文介绍了如何在不出现内存异常的情况下在MVC视图上显示大量数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上传的Excel数据超过2行。每次划分为500行的块以创建xml并命中数据库,在使用存储过程处理之后,我将返回更新的500行并存储在数据表中,并且每500行返回最多2行的行。



它的工作正常我得到了2行处理行的数据表。现在,当我重新将此数据表重新显示到视图以显示它时会抛出内存异常。



请帮助。



I am uploading an excel with data more than 2 lacs rows. Dividing into chunks of 500 rows everytime to create xml and hit the database , after processing using stored procedure i am returning the updated 500 rows and storing in a datatable and appending every 500 rows returned upto 2 lacs rows are processed.

Its working fine i get a datatable of 2 lacs processed rows. Now when i am reurning this Datatable to the View to display it throws Out Of Memory Exception.

Please help.

Controller :

  return View(validateDS.Tables[0]);





查看:





View:

@model System.Data.DataTable
@using System.Data;

<h2>Upload File</h2>

@using (Html.BeginForm("Index", "Upload", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <div class="form-group">
        <input type="file" id="dataFile" name="upload" />
    </div>

    <div class="form-group">
       
        <input type="submit" name="Command" value="Upload Cegedim" class="btn btn-default" />
     
    </div>

    if (Model != null)
    {
        <table>
            <thead>
                <tr>
                    @foreach (DataColumn col in Model.Columns)
                    {
                        <th>@col.ColumnName</th>
                    }
                </tr>
            </thead>
            <tbody>
                @foreach (DataRow row in Model.Rows)
                {
                    <tr>
                        @foreach (DataColumn col in Model.Columns)
                        {
                            <td>@row[col.ColumnName]</td>
                        }
                    </tr>
                }
            </tbody>
        </table>
    }
}

< br $> b $ b

我尝试了什么:



我已经尝试过以上代码。它适用于50k记录。现在它不适用于2个lac记录。



我知道.Net只提供2GB的数据但是必须要解决这种情况请帮忙。





1)我还想知道如何在这种情况下使用上面的代码应用分页。



What I have tried:

I have tried the above code. It worked fine for 50k records. now its not working for 2 lac records.

I know .Net provides only 2GB of data but there must be a work around for such situations Please help.


1) I also want to know how can i apply paging in this situation with the above code.

推荐答案

简单的解决方案是:不要这样做。

如前所述,这是一个坏主意。为什么?原因有三:

1)由于您作为页面发送了大量数据,因此需要占用大量带宽,显示非常非常慢。

2)如果要使用它,没有人:大多数人甚至不会第二次回到网站。部分是因为加载速度太慢,但主要是因为他们无法找到他们想要的东西。你想滚动200,000行寻找他们感兴趣的行吗?即使他们这样做了,你认为它会花多长时间?

3)正如你所看到的那样,大多数浏览器会出现内存不足错误 - 纯粹是因为HTML它所有生成都是如此巨大。



Page。过滤它。让用户搜索它。但是,不要只是把它全部扔在他身上,并希望他能把它解决掉。这是懒惰的方式 - 对你来说很简单,对用户来说毫无用处。这意味着它不会被使用。
The simple solution is: don't do it.
As has been mentioned, it's a bad idea. Why? Three reasons:
1) It's going to take a huge amount of bandwidth, and be very, very slow to display due the huge amount of data you are sending as the page.
2) Nobody if going to use it: most people won't even come back to the site a second time. Partly because it's so slow to load, but mostly because they can't find what they are looking for. Do you want to scroll though 200,000 rows looking for the row they are interested in? Even if they did, how long do you think it's going to take them?
3) It's going to crash out most browsers with an out of memory error, as you have seen - purely because the HTML it all generates is so damn huge.

Page it. Filter it. Let the user search it. But don't just dump it all on him and expect him to sort it out. That's the lazy way - easy for you, useless for the users. And that means it doesn't get used.


这篇关于如何在不出现内存异常的情况下在MVC视图上显示大量数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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