Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML page disappears when javascript is included above content
    primarykey
    data
    text
    <p>I have an ASP.NET MVC 3 site that I'm trying to enable client-side validation on but I'm running into a really strange problem. The page loads and renders just fine until I include any javascript files. Once I do, any content below the script tag disappears completely. For example, this renders just fine (note the lack of a javascript include):</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;@ViewBag.Title&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;link href="/assets/css/style.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="main"&gt; @Html.Partial("Header") &lt;div class="clr"&gt;&lt;/div&gt; &lt;div class="body_resize"&gt; &lt;div class="body"&gt; &lt;div class="left"&gt; @RenderBody() &lt;/div&gt; &lt;div class="right"&gt; @RenderSection("RightContent") &lt;/div&gt; &lt;div class="clr"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="clr"&gt;&lt;/div&gt; &lt;/div&gt; @Html.Partial("BottomSection") @Html.Partial("Footer") &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This, however, causes the entire page to be blank (note the addition of the jQuery link tag in the HEAD section):</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;@ViewBag.Title&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;link href="/assets/css/style.css" rel="stylesheet" type="text/css" /&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="main"&gt; @Html.Partial("Header") &lt;div class="clr"&gt;&lt;/div&gt; &lt;div class="body_resize"&gt; &lt;div class="body"&gt; &lt;div class="left"&gt; @RenderBody() &lt;/div&gt; &lt;div class="right"&gt; @RenderSection("RightContent") &lt;/div&gt; &lt;div class="clr"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="clr"&gt;&lt;/div&gt; &lt;/div&gt; @Html.Partial("BottomSection") @Html.Partial("Footer") &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>If I move the script link tag to the bottom of the page, it renders fine again, but I'm pretty sure I'm not getting access to the jQuery library. I tried adding this just above the script include (which is now at the bottom of the page):</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; &lt;!-- $(document).ready(function () { alert('test'); }); //--&gt; &lt;/script&gt; </code></pre> <p>My alert never fired.</p> <p>So additionally, the same thing is happening in a separate Partial View:</p> <pre><code>&lt;div id="formContainer"&gt; @using (Html.BeginForm()) { &lt;div class="tRightBoxMid tClear"&gt; &lt;p style="padding:0;"&gt; Your Name&amp;nbsp;&amp;nbsp;@Html.ValidationMessageFor(m =&gt; m.Name)&lt;br /&gt; @Html.TextBoxFor(m =&gt; m.Name, new { style = "width:275px" })&lt;br /&gt; Your Email Address&amp;nbsp;&amp;nbsp;@Html.ValidationMessageFor(m =&gt; m.Email)&lt;br /&gt; @Html.TextBoxFor(m =&gt; m.Email, new { style = "width:275px" })&lt;br /&gt; Your Message&amp;nbsp;&amp;nbsp;@Html.ValidationMessageFor(m =&gt; m.Message)&lt;br /&gt; @Html.TextAreaFor(m =&gt; m.Message, 4, 100, new { style = "width:275px" })&lt;br /&gt; &lt;input type="submit" class="formButton" value="Send Message" /&gt;&lt;div id="msgSent" style="display:none;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color='green'&gt;&lt;b&gt;Message sent! A representative will be in touch with you shortly.&lt;/b&gt;&lt;/font&gt;&lt;/div&gt; &lt;/p&gt; &lt;/div&gt; } &lt;/div&gt; &lt;script type="text/javascript" src="/Assets/js/jquery.validate.min.js" /&gt; &lt;script type="text/javascript" src="/Assets/js/jquery.validate.unobtrusive.min.js" /&gt; </code></pre> <p>My client validation is never firing (note the includes at the BOTTOM -- page renders, but I'm not getting access to the included JS). If I move it to the top, the rest of my page loads, but this partial view disappears.</p> <p>Long story short, any HTML that exists BENEATH a javascript include anywhere in my site seems to be disappearing and when I move the JS to the bottom, it's like it's not included at all. I've tried deleting all of the content from the various body and other sections to eliminate it, but it seems to be happening even when almost all markup and code is stripped out of the equation...anyone have any idea what's going on here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload