how to set values other than text using the htmlhelpers in razor

6 posts, 0 answers
  1. Gareth
    Gareth avatar
    3 posts
    Member since:
    Jun 2012

    Posted 24 Jun 2012 Link to this post

    working with a MVC4 application, and trying to get the menu to render.  

    I've tried the following code, which works fine:

     @(Html.Kendo().Menu()
               .Name("menu")
               .Items(items =>
                          {
                              items.Add().Text("Item 1");
                              items.Add().Text("Item 2");
                          }
               )
    )

    how can I set properties other than Text?  I would like to be able to reference events by the menu item ID, which I can't seem to set through the html Helpers.
  2. Lee
    Lee avatar
    2 posts
    Member since:
    Sep 2012

    Posted 06 Jul 2012 Link to this post

    I too would like this wisdom. I am new to this toolkit and razor and would love some enlightenment!

    Kind Regards,


    Lee
  3. Michael Topf
    Michael Topf avatar
    23 posts
    Member since:
    May 2010

    Posted 20 Jul 2012 Link to this post

    Hi,

    as far as i know different properties are joined together in Razor with a ".".

    So this works: 

    items.Add().Text("Home").Url("Home/About");

    As you can see there's at least a property "Url" which contains the target of the menu entry. I don't know if you can specify the controller separately. For the standard routing you can use "controller/action".

    Hope this helps,
    Michael 
  4. Lee
    Lee avatar
    2 posts
    Member since:
    Sep 2012

    Posted 20 Jul 2012 Link to this post

    Thanks Michael,

    I'll give that a go!


    Lee.
  5. Michael Topf
    Michael Topf avatar
    23 posts
    Member since:
    May 2010

    Posted 20 Jul 2012 Link to this post

    Hi Lee,

    In the sample project I have seen, there seems at least one additional parameter "Enabled". 

    items.Add().Text("News").Enabled(false);

    Unfortunately the documentation for the ASP.net MVC Wrapper seems not to be ready / published.

    Michael
  6. Samuel
    Samuel avatar
    19 posts
    Member since:
    Aug 2012

    Posted 08 Nov 2012 Link to this post

    There is also a .Action, which works well for actions. The only issue I have with it is that it doesn't work quite the same way as the razor helper. Namely, you can't include the link text with the .Action - you have to use a separate .Text() for that.
Back to Top