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

[Solved] RE: Issues using content method for panel bar

2 Answers 152 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carlos
Top achievements
Rank 1
Carlos asked on 13 Apr 2012, 03:14 PM

Hi, I'm trying to to fill a panel item with the content of a partial view using:

 

@{ Html.Telerik().PanelBar()
        .Name("PanelBar")
        .HtmlAttributes(new { style = "width: 300px; float: left; margin-bottom: 30px;" })
        //.ExpandMode((PanelBarExpandMode)Enum.Parse(typeof(PanelBarExpandMode), (string)ViewData["expandMode"]))
        .SelectedIndex(0)
        .Items(item =>
        {
            item.Add()
                .Text("Submission Information")

                .Content(() =>
                {
                    @Html.DisplayForModel("_PartialViewName.cshtml");

                });
        })
        .Render();
}

 

The problem is that the @Html.DisplayForModel("_PartialViewName.cstml") does not display it's content. Note the _PartialViewName.cshtml view is in the same directory as the view it is being displayed in.

Thanks,
Carlos

 

 

2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 16 Apr 2012, 08:18 AM
Hello Carlos,

To make things work you will need to change several things in the code you shared. 
  1. Use the @<text></text> overload of the Content method.
  2. Change the lambda variable from item to something else (e.g. items) or there will be a compiler error, since the item variable is used by MVC templates.
  3. Make sure you have passed a model to your view (from the controller)
  4. The Display template should be placed inside the Shared/DisplayTemplates folder.

Your final code should look similar to this one:
@{ Html.Telerik().PanelBar()
        .Name("PanelBar")
        .HtmlAttributes(new { style = "width: 300px; float: left; margin-bottom: 30px;" })
        //.ExpandMode((PanelBarExpandMode)Enum.Parse(typeof(PanelBarExpandMode), (string)ViewData["expandMode"]))
        .SelectedIndex(0)
        .Items(items =>
        {
            items.Add()
                .Text("Submission Information")
                .Content(@<text>
                    @Html.DisplayForModel("PartialViewName.cshtml")
                </text>);
        })
        .Render();
}

More information about the subject can be found here.

All the best,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Mahesh
Top achievements
Rank 1
answered on 23 Apr 2012, 10:39 AM
Hi Petur,

Can I achieve the same functionality while using model binding because I have to provide display, edit and submit functionalities in each panelbar item. Check the below link in which I posted my question in telerik forum for more details.

http://www.telerik.com/community/forums/aspnet-mvc/panelbar/ajax-beginform-for-each-panelbar-item.aspx
Tags
PanelBar
Asked by
Carlos
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Mahesh
Top achievements
Rank 1
Share this question
or