Menu Dynamic Item Text Issue

3 posts, 0 answers
  1. Bill
    Bill avatar
    11 posts
    Member since:
    Jul 2012

    Posted 07 Oct 2012 Link to this post

    I'm trying to use the MVC ViewBag to set an items text dynamically.  However I get error messages when I do the following:


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


    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.

  2. Bill
    Bill avatar
    11 posts
    Member since:
    Jul 2012

    Posted 14 Nov 2012 Link to this post

    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;
              .Items(items =>

  3. Jose Molina
    Jose Molina avatar
    2 posts
    Member since:
    Sep 2008

    Posted 13 May 2016 in reply to Bill Link to this post

    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 )



Back to Top