1

I have a view that simply populates the page with objects from a list in my model, but during this, Google Chrome becomes unresponsive and asks whether we want to kill the pages. This is a bit frustrating as IE and FF both work fine (loads instantaneously) and I am not about to start recommending users use IE as a short-term solution (just can't bring myself to do it).

Here is an example of where the page is dying. The loop is populating rows in a table:

For i = 0 To Model.ListOfStuff.Count - 1
    @<tr>
        <td>@Html.LabelFor(Function(d) d.ListOfStuff(i).SelectedItem, Model.ListOfStuff(i).Name)</td>
    <td>
        @Html.CheckBoxFor(Function(c) c.ListOfStuff(i).SelectedItem)
        @Html.HiddenFor(Function(c) c.ListOfStuff(i).Id)
    </td>
</tr>

Next

This contains no more than 900 records, so I'm not sure why Chrome is falling over at this.

So my question to SO, is, how do I optimise this so that Chrome does not fall over? OR, is there a known work around for Chrome becoming unresponsive? I'm clutching at straws here.

Many thanks for any help.

4
  • 1
    That code will be executed on the server side. If Chrome is becoming unresponsive its unlikely to be this. Do you have some Javascript running elsewhere? Commented Jan 22, 2015 at 10:10
  • 1
    lil confuse here. Could you change code to use 'foreach' instead of 'for' and try? Commented Jan 22, 2015 at 10:55
  • @ChrisRedhead : That's what was confusing me, but without the loop, the page loads instantly, so I'm wondering if it's not a code issue and quite likely to be a Chrome issue. There is no JavaScript running on the page, aside from a simple update element script that runs once (I added debug lines to check). Commented Jan 22, 2015 at 11:57
  • @Savaratkar : Good idea, I just tried this, but when doing a foreach you lose your direct reference to the Model list objects, so it breaks the persisting of values. That appears to be why this was done in a for loop. Commented Jan 22, 2015 at 11:59

1 Answer 1

1

In case anyone stumbles across this and is in a similar position, here is the solution to the problem.

The problem was that I was including jquery-1.7.1.js in my shared _Layout.vbhtml view, in a bundle. For some reason, although no jQuery was actively being called, this caused multiple views to crash if they included loops with quite a few records in them.

To fix this, I created a new shared layout view called "_LayoutNoScripts.vbhtml" (and removed all scripts) and set the problematic view's Layout to this instead:

@Code
    Layout = "~/Views/Shared/_LayoutNoScripts.vbhtml"
@End Code

Then, because jQuery was actually needed in the view, I included the script as an individual reference:

<script src="@Url.Content("~/scripts/jquery-1.7.1.js")"></script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.