0

I've got an asp.net mvc view with at the end the following javascript code


<script language="javascript" type="text/javascript">
      $(document).ready(
            function () {
              alert("This is a test");
            });
  </script>

 

The alert doesn't show when loading the page. I've got the following error: "Microsoft JScript runtime error: Object expected"

 

This is the section of the Site.Master:


  <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
  <link href="../../Content/Controls.css" rel="stylesheet" type="text/css" />
  <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
  <script src="../../Scripts/jquery-ui-1.8.6.custom.min.js" type="text/javascript"></script>
  <link href="../../Content/ui-lightness/jquery-ui-1.8.6.custom.css" rel="stylesheet" type="text/css" />
  <script src="../../Scripts/jquery.ui.datepicker-nl.js" type="text/javascript"></script>

 

Does anyone has an idea why I got this error? Even when I delete the alert, I've got this error.

thanks,

Filip

Filip
  • 1,098
  • 5
  • 17
  • 34

2 Answers2

1

Make sure that your scripts are included correctly, for example what you have:

<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

That may be valid for where the .master is, but an invalid relative path to where the page is, check out this question for setting relative paths to the current page in your master.

Community
  • 1
  • 1
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
1

The problemn is solved by using:

<script src="<%= Url.Content ("~/Scripts/jquery-1.4.1.min.js") %>" type="text/javascript" />
<script src="<%= Url.Content ("~/Scripts/jquery-ui-1.8.6.custom.min.js") %>" type="text/javascript" />
<script src="<%= Url.Content ("~/Scripts/jquery.ui.datepicker-nl.js") %>" type="text/javascript" />
Filip
  • 1,098
  • 5
  • 17
  • 34