Expander with a Partial?

2 posts, 0 answers
  1. Joel
    Joel avatar
    209 posts
    Member since:
    Jun 2018

    Posted 11 Mar 2019 Link to this post

    I was asked to condense one of my Razor pages by having sections create dynamically.  So, instead of bouncing the user over to a separate View they want me to stay on the same View but just expand an area in order to accommodate more input.    I thought I'd run the idea past you guys being as I have no idea how I'd accomplish this.  As a WPF programmer, I could do it there by having an Expander control with a UserControl that binds to a list of Addresses.


    Capture the information on a person using this type of flow.

    FirstName (standard field)

    LastName (standard field)


    Address 1 (push a button to expand)

    Address 2 (push a button to expand)

    Address 3

  2. Ivan Danchev
    Ivan Danchev avatar
    2184 posts

    Posted 14 Mar 2019 Link to this post

    Hello Joel,

    You could consider using the PanelBar helper (demos). It allows you to either nest arbitrary Html or to load a partial views as content of its items.

    See the Basic usage demo for example of adding Html as content, as for loading partial views in different items you can do so as demonstrated below:
        .Items(panelbar =>
                .Content(Html.Partial("/Pages/Partial1.cshtml", new Partial1Model()).ToHtmlString());
                .Content(Html.Partial("/Pages/Partial2.cshtml", new Partial2Model()).ToHtmlString());
                .Content(Html.Partial("/Pages/Partial3.cshtml", new Partial3Model()).ToHtmlString());

    Note that ToHtmlString is an extension method for IHtmlContent:
    public static class HtmlContentExtensions
        public static string ToHtmlString(this IHtmlContent htmlContent)
            using (var writer = new StringWriter())
                htmlContent.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
                return writer.ToString();

    Ivan Danchev
    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.
Back to Top