Hi All,
I am using the following code for Tree View in Ajax - Load on demand mode. I am getting an error with this code snippet. Please let me know what is wrong with this code. Appreciate any response. TIA.
@(Html.Telerik().TreeView()
.Name("AjaxTreeView")
.BindTo(Model.Products,(item, test) =>
{
item.Text = test.TreeName;
item.Value = test.TreeID.ToString();
item.LoadOnDemand = test.Children.Count > 0;
})
.DataBinding(dataBinding => dataBinding
.Ajax().Select("_AjaxLoading", "SegmentController")
))
Find below the details of my error -
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1593: Delegate 'System.Action<Telerik.Web.Mvc.UI.NavigationBindingFactory<Telerik.Web.Mvc.UI.TreeViewItem>>' does not take 2 arguments
Source Error:
Line 83: @(Html.Telerik().TreeView() Line 84: .Name("AjaxTreeView") Line 85: .BindTo(Model.Products,(item, test) => Line 86: { Line 87: item.Text = test.TreeName; |
8 Answers, 1 is accepted
For the record, I am using very similar code in an MVC project using Web Forms View Engine without a problem. The problem only occurs within a Razor view.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.Compiler Error Message: CS1593: Delegate 'System.Action<Telerik.Web.Mvc.UI.NavigationBindingFactory<Telerik.Web.Mvc.UI.TreeViewItem>>' does not take 2 arguments
Source Error:
|
Would be great if Telerik can address either the issue or what I've done wrong.
We need a sample project which reproduces this problem as we are not sure what may be causing it.
Regards,Atanas Korchev
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Problem
The TreeView controls BindTo() method was not finding the right signature. We have set our model to:
@model IEnumerable<OurViewModel>
and were trying to use the BindTo(IEnumerable<T> Model, Action <TreeViewItem, T>) signature. For whatever reason, this would not work. It always tried to use the BindTo(IEnumerable Model, Action<NavigationBindingFactory<TreeViewItem>> action) signature.
To get around this, we simply moved it over to BindTo<T> to force it to use the signature we wanted. Really not sure why this is happening.
Can you show some code or more info. I have the same problem
I have this code:
Html.Telerik().TreeView() .Name("TreeView") .BindTo<CategoryModel>(Model, mappings => { mappings.For<CategoryModel>(binding => binding .ItemDataBound((item, category) => { item.Text = category.Name; }) .Children(category => category.ParentCategoryID)); mappings.For<CategoryModel>(binding => binding .ItemDataBound((item, cat) => { item.Text = cat.Name; })); }).Render();
and also I get mappings doesnt contain method or extension "For"
Thanks
Alex.
BindTo<
CategoryModel
>(Model, mappings =>
If you use the generic form of the method the second parameter it expects should be:
(item, category) =>
If you want to use the mapping way use it like this:
BindTo(Model, mappings =>
Thanks.
I started using Telerik mvc controls recently and encountered the same issue with TreeView biding to a Model.
Sample code stated that BindTo method takes IEnumerable<T> as a first argument.
But for the new API, it takes IEnumerable interface instead.
So, declaring your model as IEnumerable resolve the issue:
@model System.Collections.IEnumerable
@(Html.Telerik().TreeView().Name("TreeView")
.BindTo(Model, mappings => {
mappings.For<Employee>((n) => {
n.ItemDataBound((i, e) =>
{
i.Value = e.Id.ToString();
i.Text = e.Name;
})
.Children(e => e.Employees);
});
})
)