admin管理员组

文章数量:1291660

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?

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?

Share Improve this question asked Mar 10, 2015 at 8:47 TraffyTraffy 2,86115 gold badges54 silver badges80 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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
}

本文标签: