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

[Solved] Set Link Attribute in Databinding

1 Answer 101 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.
David Wright
Top achievements
Rank 1
David Wright asked on 04 Feb 2011, 05:38 PM
Hi, 

I would like to set the LinkHtmlAttribue value for a menu item (to open in a new window) but this does not appear to be possible when Databinding. 

@(Html.Telerik().Menu().Name("MachineDetailsMenu").BindTo(Model.AvailableCommands, mappings =>
    {
        mappings.For<MenuViewModel>(binding =>
            binding.ItemDataBound((item, menuViewModel) =>{
                item.Text = menuViewModel.Text;
                item.Enabled = menuViewModel.Enabled;
                item.LinkHtmlAttributes = menuViewModel.HtmlAttributes;
                if(!String.IsNullOrEmpty(menuViewModel.ControllerName))
                {
                    item.ControllerName = menuViewModel.ControllerName;
                    item.ActionName = menuViewModel.ActionName;
                    item.RouteValues = menuViewModel.RouteValues;
                     
                }
            }).Children(child => child.Children));
    }))

Causes an exception (Delegate does not take 1 action). It would appear the LinkHtmlAttributes has a private setter so cannot be accessed?

Any advice would be great. 

Cheers
Dave

1 Answer, 1 is accepted

Sort by
0
Faber
Top achievements
Rank 1
answered on 07 Mar 2011, 02:51 PM
Hi David

I've the same problem but I've found a simple workaround using jQuery API.

Here the code to set HtmlAttributes class to the main menu nodes
$('#MenuID').children('.t-item').addClass('MyHtmlAttributesClass');

Here the code to set LinkHtmlAttributes to the main menu nodes
$('#MenuID').children('.t-item').children('.t-link').addClass('MyLinkHtmlAttributesClass');

I hope it's helpful.

Bye

Tags
Menu
Asked by
David Wright
Top achievements
Rank 1
Answers by
Faber
Top achievements
Rank 1
Share this question
or