I am trying to make a treeview similar to "Binding to Model" but i am using entity framework.
Could you please send me sample example related to showing data using entity framework for Treeview.
Regards
5 Answers, 1 is accepted
Providing custom samples by request is out of our support services scope, but if you send us a sample project that shows your current setup, what you have done so far and what exactly is the problem that you experience, we will check it and suggest a solution.
Georgi Tunev
the Telerik team
Hi Georgi,
My code is below to display on Treeview but it's not working.
Could you please suggest what could be the solution
//Model
namespace AusFleet.Data.Models.ReferenceFile
{
public
class PFLModelModel
{
public int MODEL_ID { get; set; }
public string MODEL_USER_CODE { get; set; }
public string MODEL_DESCRIPTION { get; set; }
}
public class PFLSeriesModel
{
public int SERIE_ID { get; set; }
public string SERIE_USER_CODE { get; set; }
public int? MODEL_ID { get; set; }
public string SERIE_DESCRIPTION { get; set; }
}
}
// Controller
public ActionResult DataBindingToModel()
{
ReferencesFiles _ReferencesFiles = new ReferencesFiles();
var _pFLModel = _ReferencesFiles.Model();
return PartialView("_PFLModel", _pFLModel);
}
//PartialView _PFLModel
@(Html.Telerik().TreeView()
.Name("TreeView")
.BindTo(Model, mappings =>
{
mappings.For<PFLModelModel>(binding => binding
.ItemDataBound((item, category) =>
{
item.Text = category.MODEL_DESCRIPTION;
})
.Children(category => category.SERIE_ID));
mappings.For<PFLSeriesModel>(binding => binding
.ItemDataBound((item, product) =>
{
item.Text = product.SERIE_DESCRIPTION;
}));
})
)
The code that you provided does not show what is the relation between the two classes. What I see is that you set .Children(category => category.SERIE_ID));. This however, should be a collection of items, not an integer as it is set in your PFLSeriesModel class.
All the best,
Georgi Tunev
the Telerik team
MODEL_ID in PFLModelModel is the foreign key in PFLSeriesModel. Connecting this to table i want to show the treeview structure as every MODEL_DESCRIPTION has its Sub node as SERIES_DESCRIPTION.
Regards
As I noted in my previous reply, the problem is that you pass an integer to the children collection while you should feed it with a collection of items. There are various resources in the Web that show how to use self-referencing binding (by the way, the Drag and Drop Treeview's demo also uses self-referencing binding)
Regards,
Georgi Tunev
the Telerik team