Question

I am Using kendo UI Treeview, there is ajax call of post method , in browser i see there is id=xx value pass but when i check by debug point in actionmethod i can't get value there is null why?

i have put code am i doing something wrong?

//View page code

 @(Html.Kendo().TreeView()
               .Name("treeview1")
               .DragAndDrop(true)
               .DataTextField("Name")
               .DataSource(dataSource => dataSource
               .Read(read => read
                   .Action("Categor", "CategorySet")
                ))

Controller Code

public ActionResult Categor(int? ID)
{
    return Json(categories, JsonRequestBehavior.AllowGet);
}

Browser Code means ajax call

GET http://www.xyz.com/Admin/CategorySet/Categor?id=2 200 OK 96ms

See in url there is ?id=2 But in Action method i can't get this 2. Why. ? How to solve this?

Thank you in advance Vinit

Was it helpful?

Solution

I think issue might be with case of ID

change ID to id

public ActionResult Categor(int? id)
{
    return Json(categories, JsonRequestBehavior.AllowGet);
}

OTHER TIPS

You pass the wrong call:

try this:

GET http://www.xyz.com/Admin/CategorySet/Categor?ID=2 200 OK 96ms

instead of this:

GET http://www.xyz.com/Admin/CategorySet/Categor?id=2 200 OK 96ms

  • Please note Read action is an asynchronous call and on load i.e on first call id will be null always
  • For Ex:
    Parent1 ID 7--> Child1 ID 8
    Parent2 ID 9--> Child2 ID 6--> SubChild1 ID 5

  • On First Load id's will be NULL if you press Continue(F5) on second call you will receive ID 7 to get its children .. like this this action will be called until you reach last child

Hope you got it.. because its working fine for me

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top