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

Treeview is not pasing the id to controller when expanding leaf

1 Answer 132 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 03 Mar 2016, 08:09 PM

I have an MVC Treeview identical to the Treeview Binding Remote Data code sample as well as the one if the video Kendo UI for ASP.NET MVC TreeView but I cannot seem to get the Id to be passed to my controller when the tree is expanded.

The examples show the id being passed in the querystring.

@(Html.Kendo().TreeView()
    .Name("my-Tree-View")                   
    .DataTextField("Name")                   
    .DataSource(dataSource => dataSource                       
    .Read(read => read
        .Action("GetSourcesByID", "source")
     ))
 )

My initial results look like this and my Tree appears to be properly displayed:

[{"Id":"AK","Name":"AK","hasChildren":true},{"Id":"AL","Name":"AL","hasChildren":true},{"Id":"AR","Name":"AR","hasChildren":true},...]

In case it matters here is my controller:

public ActionResult getSourcesByID(string id)
    {
    IList<TreeViewModel> sourceVM = new List<TreeViewModel>();
     if (id == null)
        {
        var QueryStates = from source in context.states
                    select new
                        {
                        state = source.state1 ,
                        };
        foreach (var prod in QueryStates)
            {
            sourceVM.Add(new TreeViewModel { Id = prod.state, Name=prod.state, hasChildren=true });
            }
        } else
        {
        var Query = from source in context.sources
                    where source.state == id
                    select new
                        {
                        sourceid = source.sourceid,
                        state = source.state,
                        sourcename = source.sourcename
                        };
        foreach (var prod in Query)
            {
            sourceVM.Add(new TreeViewModel { Id = prod.sourceid.ToString() , Name = prod.sourcename, hasChildren=false });
            }
 
        }
    return Json(sourceVM, JsonRequestBehavior.AllowGet);
    }

What else do I need to do to force it to send the ID?

Brad

 

1 Answer, 1 is accepted

Sort by
0
Brad
Top achievements
Rank 1
answered on 03 Mar 2016, 08:16 PM

Ok, just figured it out.

The Id property must be all lower case: id.

- Brad

 

Tags
TreeView
Asked by
Brad
Top achievements
Rank 1
Answers by
Brad
Top achievements
Rank 1
Share this question
or