Linking jQuery UI to the ASP.NET MVC 2 project
What I am trying to accomplish is using jQuery UI dialog method from my own JavaScript source code file. I have this kind of links in the Site.Master
<script src="/Scripts/jquery-1.4.2.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.js" type="开发者_StackOverflow中文版text/javascript"></script>
<script src="/Scripts/jquery-ui.js" type="text/javascript"></script>
<script src="/Scripts/Common.js" type="text/javascript"></script>
Common.js is my own helper file. jQuery works fine there, but when I try to call for example:
$(document).ready(function() {
$("#dialog").dialog();
});
I'll get "Microsoft JScript runtime error: Object doesn't support this property or method"
Any ideas why this happens? jQuery Works fine, but jQuery UI doesn't.
Additional question: if I use jquery-ui.js, do I need other files like core, dialog etc. or does it really contain everything?
Can you confirm that the script references are being loaded? Startup firebug or fiddler and see if you get any 404s.
The following works for me on coderun.com
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQueryUIV172Application</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css"
type="text/css" media="all" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script src="index.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#dialog").dialog();
})
</script>
</head>
<body>
<div id="dialog">
Hello
</div>
</body>
</html>
Also you might try loading up references to JS files like this:
<script src="<%=Url.Content("~/Scripts/jquery-1.4.2.js")%>" type="text/javascript"></script>
I found the problem. I have been using "Telerik Extension for ASP.NET MVC" and it has function called ScriptRegistrar (is that even a word?) which I had to use like this:
<%= Html.Telerik().ScriptRegistrar().DefaultGroup(group =>
group.Add("~/Scripts/jquery-1.4.2.min.js")
.Add("~/Scripts/jquery-ui-1.8.1.custom.min.js")
.Add("~/Scripts/jquery.validate.js")
.Add("~/Scripts/Common.js")
)
%>
Big thanks to everyone who helped me with this problem!
Seems like you ahve to register all your script files through this magic 'Registrar' method from Telerik, otherwise the other scripts in the page won't work.
精彩评论