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

Set panelbar text with ViewBag value

3 Answers 463 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 07 Jan 2019, 05:22 PM

Is there a way to set a panelbar individual panel title text with a ViewBag value instead of a literal string?  In my code on line 7, the text is set as "Not Submitted". But I would like to populate it with a string value I build and place in Viewbag that shows a count of records for the type of "Not Submitted". It would read like this - "Not Submitted - (20)".  If it's possible, what would be the syntax to use a variable/constant instead of literal string?

                                     

01.@(Html.Kendo().PanelBar()
02..Name("panelbar")
03..ExpandMode(PanelBarExpandMode.Single)
04..HtmlAttributes(new { style = "width:100%" })
05..Items(panelbar =>
06.{
07.      panelbar.Add().Text("Not Submitted")
08.        .Expanded(false)
09.}

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 09 Jan 2019, 07:59 AM
Hello Amy,

You can use "server" code just about anywhere in a view, including in HTML helpers. Here's an example I made for you that shows three examples, and the result is attached below.

public ActionResult Index()
{
    ViewBag.myHeaderText = "Not Submitted - (20)";
    ViewBag.myPlainContentText = "lorem ipsum dolor sit amet";
    ViewBag.anotherHeaderData = 33;
    return View();
}
@(Html.Kendo().PanelBar()
    .Name("panelbar")
    .ExpandMode(PanelBarExpandMode.Single)
    .HtmlAttributes(new { style = "width:100%" })
    .Items(panelbar =>
        {
            panelbar.Add().Text("Not Submitted")
                .Expanded(false);
            panelbar.Add().Text(ViewBag.myHeaderText).Content(ViewBag.myPlainContentText);
            panelbar.Add().Text("Not Submitted - (" + ViewBag.anotherHeaderData + ")");
        }
    )
)


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Accepted
Amy
Top achievements
Rank 1
answered on 09 Jan 2019, 03:06 PM

Yes, that is how I've been trying to code it.   And it works if the panel content is just a string.  But I have a kendo grid as the content.  If I set the panel.Text to the Viewbag value, errors appear on the grid code.  The error is "Cannot use lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type."  

I was able to figure out that I needed a cast to string on the ViewBag value in the index and that fixed the problem. 

panelbar.Add().Text((string)ViewBag.myHeaderText)

 

0
Marin Bratanov
Telerik team
answered on 10 Jan 2019, 09:41 AM
It's good to hear you have this resolved, Amy.

I am marking your post as the answer to this thread for anyone else having a similar scenario.

--Marin

Tags
PanelBar
Asked by
Amy
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Amy
Top achievements
Rank 1
Share this question
or