You must Sign In to post a response.
  • Category: ASP.Net MVC

    HTML table inside foreach loop in MVC is performing too slow

    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.Devices)
    {
    <tr>
    <td>
    @Html.DisplayFor(mod => device1.status)
    </td>
    <td>
    @Html.DisplayFor(mod => device1.Address)
    </td>
    </tr>
    }

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

    Regards,
    Raj
  • #763385
    Hello Raj

    The @foreach which you are using in the razor view is 100% correct.

    There records which is rendering as html control in the page is depends on your Server/Client speed.

    Ex. You are rending about 50K records. If you go for aspx page. This will take more than 10 mins.

    Suggestion.

    1. you can go for pagination. Show only first page records.
    2. Remove

    @Html.DisplayFor(mod => device1.status)

    Add

    <input id="status" name ="status" value= "@device1.status">

    By Nathan
    Direction is important than speed


Sign In to post your comments