How to add Custom HtmlHelper link as menu item?

3 posts, 1 answers
  1. Labrat45
    Labrat45 avatar
    17 posts
    Member since:
    Jul 2012

    Posted 04 Apr 2013 Link to this post


    I have a custom html helper as:

    in razor view:
    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>

    <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. Answer
    Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 08 Apr 2013 Link to this post

    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:

        .Items(menu => {
            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!
  3. Labrat45
    Labrat45 avatar
    17 posts
    Member since:
    Jul 2012

    Posted 09 Apr 2013 Link to this post

    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
Back to Top