'I can't get object with ajax with ASP.NET MVC model

file js:

window.onload = function () {
    var url = window.location.pathname;
    var id = url.substring(url.lastIndexOf('/') + 1);
    $(document).ready(function () {
        $.ajax({
            data: { id, id },
            url: "/Image/getAnnotation",
            method: "GET",
            success: function (data) {
                console.log(data)
            },
            error: function (err) {
                console.log(err)
            }
        });
    }); 
}

C# function in ImageController:

public JsonResult getAnnotation(int image_id)
{
    Root items = new Root();
    items = items.init();

    var result = from item in items.annotations
                 where item.image_id == image_id
                 select item;

    return Json(result);
}

I get image_id from url, but when next page it's always image_id = 0

when image_id=1 but data get image_id =0

I want the function in C# to get image_id from Ajax



Solution 1:[1]

public JsonResult getAnnotation(int id)
{
    Root items = new Root();
    items = items.init();

    var result = from item in items.annotations
                 where item.image_id == id
                 select item;

    return Json(result);
}

i just change name variable image_id to id

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hacam308