Using @ViewBag in Title of MobileView

3 posts, 0 answers
  1. Mike
    Mike avatar
    4 posts
    Member since:
    Apr 2015

    Posted 03 Jun Link to this post

    This isn't really specific to MobileView but I'm using a MobileView in a partial view that I'm using as a layout template and I want to make the Title dynamic by using ViewBag.Title as the string.

    @(Html.Kendo().MobileView()
                    .Title(ViewBag.Title)
                    .Name("two-drawer-home")
                    .Header(obj => Html.Kendo().MobileNavBar().Content(navbar =>
                        @<text>
                            @(Html.Kendo().MobileButton().Name("btnLeftDrawer").Align(MobileButtonAlign.Left).Rel(MobileButtonRel.Drawer).Url("#left-drawer").ClickOn("down"))
                            @navbar.ViewTitle("Hello there")
                            @(Html.Kendo().MobileButton().Name("btnRightDrawer").Align(MobileButtonAlign.Right).Rel(MobileButtonRel.Drawer).Url("#right-drawer").ClickOn("down"))
                        </text>)
                    .HtmlAttributes(new { style = "height: 46px;" })
                    )
                    .Content(@<text>@RenderBody()</text>)
    )

     

    But this isn't valid. I've also tried @ViewBag.Title and various other incarnations. I'm wondering if this type of thing is possible in the Title of the MVC controls. 

  2. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 07 Jun Link to this post

    Hi Mike,

    You can try assigning the ViewBag.Title value to a string variable first and then assign this variable to the Title method. 

    @{
        string title = ViewBag.Title;
    }
     
    @(Html.Kendo().MobileView()
        .Title(title)
        ...
    )


    Regards,
    Ianko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Mike
    Mike avatar
    4 posts
    Member since:
    Apr 2015

    Posted 07 Jun in reply to Ianko Link to this post

    Awesome! Pretty simple and works (of course). Thanks very much. 
Back to Top