ASP.NET MVC Razor: Way to optimize for loop to avoid System.OutOfMemoryException [closed]

1

Good morning, basically my question is that: I have an mvc razor application that loads a data context with several tables and views. Once loaded all the models (in my viewmodel) armo grillas using for loops in the following way:

@for (int i = 0; i < Model.Grilla.Count; i++)
{
<tr id="@Model.Grilla[i].campo1">
   <td>
     @Html.DisplayFor(x => Model.Grilla[i].campo1)
   </td>
   <td>
     @Html.DisplayFor(x => Model.Grilla[i].campo2)
   </td>
</tr>

}

... 4 more grids

The problem I have when executing, being a lot of records (400 per grid) and many grids (approx 6) and all generated at the same time, I exploited the memory of Visual Studio 2015, showing me the following error:

  

An exception of type 'System.OutOfMemoryException' occurred

The particular thing about this error is that it only occurs when I want to debug from Visual Studio, if I publish the website and execute it, it runs without major problems (although it takes about 20-30 seconds to boot).

My question is this:

-Is there a way to prevent the for loops from being called at the same time? (like using a flag or calling each other at the end of each one, or giving them an execution number)

-Is there any way to put an "index" to the loop for faster data handling?

-Is there a faster way to use for loop?

-Any way to execute the for loop from JQuery / Javascript to prevent the page from loading them at the same time? (without having to rewrite all the code of the grid in javascript)

Thanks !!

    
asked by seojedaperez 16.06.2017 в 16:45
source

1 answer

0

First of all, thank you very much for the help. I already found the error: basically it was caused by the excess of grids that I loaded on my html page. This error was not generated in the model, nor in the controller, it was only generated in the View when it loaded all the data. I understand that this problem occurred in my compiler and not in the web browser because the compiler invisibly incorporated several control points x each row, doubling its size which in itself was considerable.

Also I had my duplicate view in the layout, that caused the memory to explode. I solved it by removing the duplicated view (correcting the coding that duplicated it).

    
answered by 19.06.2017 / 21:36
source