[英]ASP.NET MVC - Uncaught ReferenceError: jQuery is not defined even if I'm including the library
I'm using ASP.NET MVC 4 and I'm trying to pass a value from my JavaScript to my Controller Action. 我正在使用ASP.NET MVC 4,并且试图将JavaScript中的值传递给Controller Action。 Here's what I'm trying to do in my JavaScript :
这是我要在JavaScript中尝试做的事情:
function DoubleClick() {
debugger;
var id = 1;
$.ajax({
type: "POST",
url: "/Home/GetAppId",
data: { id: id}
});
}
And my action (really simple action) : 我的动作(真的很简单):
public JsonResult GetAppId(int id)
{
//some code will be included here
}
In my layout template, I'm including correctly my scripts (actually I'm using JS in some ohter pages and it works) : 在我的布局模板中,我正确地包含了我的脚本(实际上,我在其他页面中使用了JS,它可以工作):
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery.validate.globalize.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/jquery-ui-1.10.4.custom.min.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.custom.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.core.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.datepicker.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/DatePickerReady.js")" type="text/javascript"></script>
When I'm opening the Chrome dev tool (F12), I'm seeing the following error message in the console tab : 当我打开Chrome开发工具(F12)时,在控制台标签中看到以下错误消息:
Uncaught ReferenceError: jQuery is not defined
未捕获的ReferenceError:未定义jQuery
I can't really see where the problem is. 我真的看不出问题出在哪里。 Any idea?
任何想法?
jQuery.Validate uses jQuery. jQuery.Validate使用jQuery。
<script src="@Url.Content("~/Scripts/jquery.validate.globalize.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.js")" type="text/javascript"></script>
Should be like this: 应该是这样的:
<script src="@Url.Content("~/Scripts/jquery.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.globalize.min.js")" type="text/javascript"></script>
As to why your JavaScript is not posting back the Value that is another error. 至于为什么您的JavaScript没有回发另一个错误的值。
In Ajax you using "POST". 在Ajax中,您使用“ POST”。 Put a HttpPost Attribute on your method.
在您的方法上放置一个HttpPost属性。
[HttpPost]
public JsonResult GetAppId(int id)
{
//some code will be included here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.