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

How to add Custom HtmlHelper link as menu item?

2 Answers 194 Views
Menu
This is a migrated thread and some comments may be shown as answers.
HSO
Top achievements
Rank 2
HSO asked on 04 Apr 2013, 03:03 PM
Hello:

I have a custom html helper as:

in razor view:
@Html.LanguageToggleLink(null)
it's definition:
public static MvcHtmlString LanguageToggleLink(this HtmlHelper helper, IDictionary<string, object> htmlAttributes)
{
...
}

it's html output to Browser is either:
<a href="/projectname/fr-ca">français</a>

or
<a href="/projectname/en-ca">english</a>

it basically a language toggle link to change interface language between english and french, by injecting \en-ca or \fr-ca to the route.  {language}/{controller}/{action}/{id}

I don't know how to add this control to the menu.  Please advise,

Thank you,

2 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 08 Apr 2013, 08:25 AM
Hello Jason,

Basically to add the result of the MVC helper to be the item in the Menu widget you need to use its Text method in combination with the Encoded option set to false.

Here is an example using the CheckBox helper, same should go with your helper:

@(Html.Kendo().Menu()
    .Name("menu")
    .Items(menu => {
        menu.Add().Text("Home").Text(Html.CheckBox("test").ToHtmlString()).Encoded(false);
        menu.Add().Text("About").Action("About", "Home");
}))

I hope this helps.

Kind regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
HSO
Top achievements
Rank 2
answered on 09 Apr 2013, 05:08 AM
Thank you Petur,
However, right now I can't verify your solution, because I've changed my approach of setting up the Toggle link, I put it directly in the Layout page, instead of inside a Menu, which it in turn in a partial view.

it's good to know I can declare menu control this way, like chaining up the text(), I believe it will work, so I will make it as Answer.

Thank you
Tags
Menu
Asked by
HSO
Top achievements
Rank 2
Answers by
Petur Subev
Telerik team
HSO
Top achievements
Rank 2
Share this question
or