This project is read-only.

script in partial view

Topics: Troubleshooting
Feb 10, 2012 at 10:50 AM

In my partial view i want to add a script, but i keep getting the Error: '$' is undefined, when i render the view.

Here is an example:

@model TestModule.Models.Test

<script type="text/javascript">
(document).ready(function () {
('partial is ready.');

<h1>This is my <%: %> partial view</h1>

Can someone give me a hint on whats the problem?, i have tried to put the script in a file and link it but it doens´t help.


Feb 10, 2012 at 11:03 AM

To make sure jQuery is included you need:




Feb 10, 2012 at 12:23 PM

I have added Script.Require("jQuery"); but i still gets the same error, is this a problem when my view is a parital view? or do anyone else have any ideas?


Feb 10, 2012 at 12:32 PM

You could try Script.Require("jQuery").AtHead() to ensure that jQuery is loaded before your script executes.

Feb 10, 2012 at 12:47 PM

.AtHead made it!, thx for the help