Reputation: 2861
I'm using ASP.NET MVC 4 and I'm trying to pass a value from my JavaScript to my Controller Action. Here's what I'm trying to do in my 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) :
<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 :
Uncaught ReferenceError: jQuery is not defined
I can't really see where the problem is. Any idea?
Upvotes: 2
Views: 19488
Reputation: 7328
jQuery.Validate uses 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.
In Ajax you using "POST". Put a HttpPost Attribute on your method.
[HttpPost]
public JsonResult GetAppId(int id)
{
//some code will be included here
}
Upvotes: 6