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

[Solved] Menu works in one Tab, not in two others

2 Answers 78 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Martin
Top achievements
Rank 1
Martin asked on 06 Apr 2012, 11:21 PM
I'm using the Telerik TabStrip and Menu controls. I have a Menu that's working in one tab but shows no sub-items in the other two tabs.
Here's a rough overview.
  1. I have a main page, call it MyView.cshtml. It has a Model of MyViewModel; and MyViewModel contains three Person objects, PersonA, PersonB, and PersonC.
  2. In MyView.cshtml is a TabStrip with three tabs, A, B, and C. These are populated using Html.EditorFor(Model.PersonA), Html.EditorFor(Model.PersonB), and Html.EditorFor(Model.PersonC).
  3. I have an editor template, Person.cshtml; and in this template (among other items for editing a Person) is a Copy To menu. This is supposed to (eventually) let us copy A to B or C, B to A or C, and C to A or B. Contents of PersonA, etc., are correctly shown in the different tabs, so I know that the views are correctly tied to the different Person objects.
  4. I have a property CopyTargets in Person that populates a hierarchy of MenuItem. At the top is an item, text = "Copy To". Under that are the items that represent valid targets for this Person.

Here's the snippet that defines the menu:

@{Html.Telerik().Menu()
    .Name("copyToMenu")
    .BindTo(Model.CopyTargets).Render();
        }

Here's the code for CopyTargets:

       public List<MenuItem> CopyTargets
       {
           get
           {
               List<MenuItem> items = new List<MenuItem>();
               MenuItem root = new MenuItem { Text = "Copy To" };
               items.Add(root);
               foreach (string name in GetCopyTargets())
               {
                   MenuItem target = new MenuItem { Text = name };
                   root.Items.Add(target);
               }
               return items;
           }
       }


(GetCopyTargets is the method that gets the list of targets for each Person.)

When I run this, the Copy To menu appears in Tab A, Tab B, and Tab C; but the menu items only appear in Tab A. I have put a breakpoint in CopyTargets and verified that it gets called three times and that it adds two child items to each one.

Any suggestions of how to make the menu items appear on all three tabs?

Thanks!

Martin

2 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 11 Apr 2012, 03:57 PM
Hello Martin,

I suspect that the behavior you described is because all the Menu components you are rendering are using the same id (i.e. "copyToMenu"). You should try to define different names for each of the Menus.
If this is not the case I would like to ask you to send us a small sample project which replicates the issue so we can check the exact setup.

Regards,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Martin
Top achievements
Rank 1
answered on 11 Apr 2012, 04:31 PM
Thanks, Peter. Yes, that was the problem.
Tags
Menu
Asked by
Martin
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Martin
Top achievements
Rank 1
Share this question
or