2

I'm fairly new to MVC and I'm trying to figure out how to add jquery to an empty MVC project.

I first added several js files to my project by installing several Nuget packages. Then I added the following to my my layout file.

<head>
    ...
    <script src="~/Scripts/jquery-2.0.3.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
</head>

Now when I run the project I get the following javascript error.

 JavaScript runtime error: 'JSON' is undefined

When am I missing?

Thanks

3
  • 1
    What browser you get that? Commented Oct 17, 2013 at 19:00
  • Take a look at these SO Questions: stackoverflow.com/questions/12197323/… & stackoverflow.com/questions/4311783/… These may help you sort out what you need/should be doing. Commented Oct 17, 2013 at 19:08
  • "JavaScript runtime error: 'JSON' is undefined" error might appear in old IE browsers. Take a look at Json2.js library Commented Oct 17, 2013 at 19:56

3 Answers 3

0

In order to get MVC to recognize what the tilde means, you need to use:

<head>
    ...
    <script src="@Url.Content("~/Scripts/jquery-2.0.3.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>
</head>

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

Apparently the newest version of jQuery that the jQuery Nuget packages installs drops support for IE 6, 7, and 8. And also won't work in IE 9 or 10 if it loads in compatibility mode.

I added the following to my layout page to tell IE not to run in compatibility mode.

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

It seems to be working fine now.

Comments

0

Put this in the head element of your cshtml or aspx:

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

X-UA-Compatible meta tag allows web authors to choose which version of Internet Explorer the page should be rendered.

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.