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

Menu Dynamic Item Text Issue

2 Answers 233 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 08 Oct 2012, 01:31 AM
I'm trying to use the MVC ViewBag to set an items text dynamically.  However I get error messages when I do the following:

items.Add().Text(ViewBag.AppContext.UserDisplayName)

However, if I do something like the below, it works.  So I think it has to do with the ViewBag not being available (timing).

items.Add().Text(User.Identity.Name)

Here's the error when I try and use ViewBag data - CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.

Thoughts?

2 Answers, 1 is accepted

Sort by
0
Bill
Top achievements
Rank 1
answered on 14 Nov 2012, 07:07 PM
I figured a way around it, declare a variable before you create the menu and use the variable instead of the ViewBag when setting the menu text like so:

@{
    string displayName = ViewBag.AppContext.UserDisplayName;
 
    @(Html.Kendo().Menu()
          .Name("userMenu")
          .OpenOnClick(true)
          .Items(items =>
          {
              items.Add().Text(displayName)


0
Jose Molina
Top achievements
Rank 1
answered on 13 May 2016, 07:29 PM
I know this is an old topic. Just in case someone else come across this topic.
 
There is no need to declare a separate variable at least on the latest version of Kendo.

Do cast "UserDisplayName" to string as follows:

items.Add().Text( (String) ViewBag.AppContext.UserDisplayName )

 

regards,

Tags
Menu
Asked by
Bill
Top achievements
Rank 1
Answers by
Bill
Top achievements
Rank 1
Jose Molina
Top achievements
Rank 1
Share this question
or