This is a migrated thread and some comments may be shown as answers.

Call GET with param to populate grid

4 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 07 May 2012, 09:52 PM
I'm trying to call an MVC controller action to populate my grid and I need to pass a parameter to it. However, my breakpoint in the action isn't getting hit. Am I doing something wrong here? I can't tell if my param is making it through since my breakpoint isn't getting hit. Do I need to set up a route for this call?

Action:

[HttpGet]
public JsonResult GetSalesHistory(string id)
{
    List<Sales> sales = PestsLogic.GetSalesById(5);
    return Json(new { data = sales, total = sales.Count }, JsonRequestBehavior.AllowGet);
}

JavaScript code:

<script type="text/javascript">
    $("#grid").kendoGrid({
        dataSource: {
            type: "json",
            transport: {
                read: {
                    url: "Sales/GetSalesHistory",
                    dataType: "json",
                    type: "GET",
                    contentType: "application/json; charset=1-8",
                    data: { id: "@ViewBag.CustomerEstimateKey" }
                }
            },
            pageSize: 15,
            schema: {
                data: "data",
                total: "total"
            }
        },
        pageable: true,
        sortable: true
    });
</script>

4 Answers, 1 is accepted

Sort by
0
Jonas
Top achievements
Rank 1
answered on 08 May 2012, 09:30 AM
Try removing the "contentType".  You are not posting JSON to the server, you are performing a GET with url parameters.

Alternatively, change it to a POST.
0
Jay
Top achievements
Rank 1
answered on 08 May 2012, 02:52 PM
Neither of those things worked.
0
Daniel
Telerik team
answered on 11 May 2012, 08:31 AM
Hello Jay,

The problem could be caused by the URL in the configuration - the current URL will be prepended. You can add a forward slash in front("/Sales/GetSalesHistory") to avoid this. Also, if the script is used in the View you can use the Url.Action helper to generate the correct address e.g.
url: '@Url.Action("GetSalesHistory", "Sales")'


All the best,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jay
Top achievements
Rank 1
answered on 11 May 2012, 04:23 PM
That worked! Thank you!
Tags
Grid
Asked by
Jay
Top achievements
Rank 1
Answers by
Jonas
Top achievements
Rank 1
Jay
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or