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

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

5 Answers 153 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Gareth
Top achievements
Rank 1
Gareth asked on 25 Jun 2012, 04:27 AM
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.

5 Answers, 1 is accepted

Sort by
0
Lee
Top achievements
Rank 1
answered on 06 Jul 2012, 04:04 PM
I too would like this wisdom. I am new to this toolkit and razor and would love some enlightenment!

Kind Regards,


Lee
0
xclirion
Top achievements
Rank 1
answered on 20 Jul 2012, 12:25 PM
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 
0
Lee
Top achievements
Rank 1
answered on 20 Jul 2012, 12:28 PM
Thanks Michael,

I'll give that a go!


Lee.
0
xclirion
Top achievements
Rank 1
answered on 20 Jul 2012, 12:40 PM
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
0
Samuel
Top achievements
Rank 2
answered on 08 Nov 2012, 08:29 PM
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.
Tags
Menu
Asked by
Gareth
Top achievements
Rank 1
Answers by
Lee
Top achievements
Rank 1
xclirion
Top achievements
Rank 1
Samuel
Top achievements
Rank 2
Share this question
or