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

Dynamically Pass RouteValueDictionary values

2 Answers 971 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Abinash
Top achievements
Rank 1
Abinash asked on 11 Feb 2019, 07:22 PM

Hi,

I have a treeview and I want to bind hierarchical data. 

Country

State

Offices in State

I want to make call to the controller and get the data based on the node that is being expanded. To get the right data I want send the parameter of the currently selected node (Id, level) so that I can get the appropriate data to expand. 

 @(Html.Kendo().TreeView()
              .Name("exampleTreeView")
              .LoadOnDemand(true)
              .Checkboxes(checkboxes => checkboxes
                  .Name("checkbox")
                  .CheckChildren(true)
              )
              .Events(events => events
                  .Check("onCheck")
              )
              .DataTextField("Name")
              .DataSource(dataSource => dataSource
                  .Model(model=>model.Id("Value").HasChildren("HasChildren"))
                  .Read(read => read.Action("GetData", "MyController"))
              )
              )

Right now I can get the first set of data from getdata method and bind it. want to expand a nde which will call the same action method with some additional data to get the right data. 

I have two questions - 

1. (How) can I attach or bind additional property (level which could be country,state or office)

2. How can I pass this value to the GetData Action to get the right data.

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 14 Feb 2019, 09:21 PM
Hi Abinash,

The correct way to send additional parameters with the read request is to use the Data() method which specifies a JavaScript function that is responsible for attaching the parameters:
.Read(read => read.Action("GetData", "MyController").Data("additionalInfo"))
...
 
<script>
  function additionalInfo() {
    return {
      name: "test",
      id: 2
    }
  }
</script>

Then, the additional parameters can be successfully received on the server:
public ActionResult GetData([DataSourceRequest] DataSourceRequest request, string name, int id) {
  ...
}

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Abinash
Top achievements
Rank 1
answered on 14 Feb 2019, 10:12 PM
Thank you.
Tags
TreeView
Asked by
Abinash
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Abinash
Top achievements
Rank 1
Share this question
or