Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:38:45+00:00 2026-06-09T12:38:45+00:00

I just created an ASP .NET MVC 4 WebAPI project. In looking at the

  • 0

I just created an ASP .NET MVC 4 WebAPI project.

In looking at the default _Layout.cshtml, I see that the jquery script is being inserted after the body is rendered (not in the head).

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/themes/base/css", "~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    @RenderBody()

    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts", required: false)
</body>
</html>

This causes the error

$ is not defined 

of course, trying to write

$(document).ready(function() {...}).

Moving the

@Scripts.Render("~/bundles/jquery")

into the head section of the _Layout.cshtml corrects the problem and jquery works as expected.

What’s up? Am I doing something wrong and there’s a reason for the default location of the Script.Render inside _Layout.cshtml?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:38:46+00:00Added an answer on June 9, 2026 at 12:38 pm

    Script loading and executing block the rendering of the page.

    You can see this by adding alerts in multiple parts of your page. That’s why it’s recommended to put the js files at the back of the page.

    You can also remedy your problem by having a section for page scripts behind the one where jquery is added, at the end of the page.

    Edit: Here’s an article from Scott Guthrie about sections in razor: http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC 3 project that I just created using the project
I'm new to asp.net mvc. I just created the default asp.net mvc project in
I've just created asp.net mvc 4 app and added default webapi controller public class
I just created a ASP.NET MVC project and was able to build and browse
I've just installed ASP.NET MVC on my Vista x64 box, and created a default
I am completely new to ASP.Net MVC. I just created an MVC3 project in
I'm just starting out learning ASP.NET MVC. I'm working on a project created with
I just created a ASP.NET MVC project in VS2008. When I press F5 to
I'm just starting out with ASP.net MVC 3 and I've created an empty project.
I've just created a fresh ASP.NET MVC 4 solution and have added 3 Areas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.