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

[Solved] tabstrip within tabstrip

1 Answer 34 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sushruth
Top achievements
Rank 1
Sushruth asked on 20 Apr 2011, 06:21 AM

Here is code slice from cshtml file named "_TabPartial.cshtml" .

Html.Telerik().TabStrip().Name("ttl"+ TelerikMvcApplication2.Domain.Class1.GetX ).Items(items =>
{
    //foreach (System.Xml.Linq.XElement x in Model.Elements())
    for(int i = 0; i < Model.Elements().Count(); i++ )
    {
        System.Xml.Linq.XElement x = Model.Elements().ToList()[i];
        //add a tab
        items.Add().Text(x.Attribute("Name").Value).Content(() =>
        {
            Html.RenderPartial("_TabPartial", x); // Call self
        });
    }
      
}).Render();

.
Above code works , but if the looping construct is changed to foreach then the code

Content(() =>
        {
            Html.RenderPartial("_TabPartial", x);
        });
executes only for the last element. Should this be fixed?

Thanks
Sush

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 20 Apr 2011, 07:07 AM
Hi Sushruth,

I don't think this is a Telerik issue. This is rather the normal behavior of C# closures. The x variable is captured by reference and thus the last value is used. 

 You can check this stackoverflow answer for a reference and additional info. This blog post also discusses the same matter.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TabStrip
Asked by
Sushruth
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or