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

Problem with MVC TreeView LoadOnDemand

8 Answers 201 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
InfoSeeker
Top achievements
Rank 1
InfoSeeker asked on 21 Apr 2011, 05:36 PM

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

Sort by
0
InfoSeeker
Top achievements
Rank 1
answered on 23 Apr 2011, 07:10 PM
It will be great if i get any feedback from Telerik Support centre or anyone in the forum who has faced this problem.  The MVC TreeView code snippet for Load on Demand in Razor is not working. 
0
Alec
Top achievements
Rank 1
answered on 13 Jul 2011, 12:22 AM
So is there any resolution for this? I am experiencing the exact same issue. Have tried the sample application from the latest release and am getting the same error.

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:

Line 9:          .TreeView()
Line 10:         .Name("OrganizationTreeView")
Line 11:         .BindTo(Model, (item, org) =>
Line 12:         {
Line 13:             // bind initial data - can be omitted if there is none

Would be great if Telerik can address either the issue or what I've done wrong.
0
Atanas Korchev
Telerik team
answered on 13 Jul 2011, 07:11 AM
Hi Alec,

 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!

0
Alec
Top achievements
Rank 1
answered on 13 Jul 2011, 05:44 PM
We were able to solve the problem, more on that below. I will also provide a sample sometime this weekend that shows the problem (if I can reproduce outside our project).

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. 
0
sasho
Top achievements
Rank 1
answered on 25 Aug 2011, 07:33 PM
Alec,

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.
0
Nohinn
Top achievements
Rank 1
answered on 31 Aug 2011, 03:54 PM
sasho in your case your problem is the
BindTo<CategoryModel>(Model, mappings =>
part.

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 =>

0
Gregor
Top achievements
Rank 1
answered on 04 Nov 2011, 10:17 AM
Hey Alec, could you explain a bit more in detail how did you solve your problem, cause I have exactly the same problem as InfoSeeker provided.

Thanks.
0
Rustam
Top achievements
Rank 1
answered on 12 Feb 2012, 08:10 PM
Hi.

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);
        });
    })
)
Tags
TreeView
Asked by
InfoSeeker
Top achievements
Rank 1
Answers by
InfoSeeker
Top achievements
Rank 1
Alec
Top achievements
Rank 1
Atanas Korchev
Telerik team
sasho
Top achievements
Rank 1
Nohinn
Top achievements
Rank 1
Gregor
Top achievements
Rank 1
Rustam
Top achievements
Rank 1
Share this question
or