Nested partials in razor view

  1. #1

    Nested partials in razor view

    Hello everyone, I want to render a page with at least 2 partial levels, something like this:

    _Main.cshtml
    @model IEnumerable<Category>
    
    @(Html.X().ResourceManager())
    
    @{
        var mainPanel = new Panel().ToBuilder().Title("Category info").Width(800);
        foreach (var category in Model)
        {
            mainPanel.ItemsFromPartial("_Category", category);
        }
    }
    
    @mainPanel
    _Category.cshtml
    @model Category
    
    @{
        var categoryPanel = new Panel().ToBuilder().Title(Model.Name).Width(750);
    
        foreach (var item in Model.Items)
        {
            categoryPanel.ItemsFromPartial("_Item", item);
        }
    }
    
    @categoryPanel
    And _Item.cshtml with some text within.

    I've been following the example from here but only the main panel was rendered with nothing in its body.

    I wonder if I did it right, or is there another way to use loop inside method Items()?
  2. #2
    Hi @vinhmt,

    Welcome to the Ext.NET forums!

    And _Item.cshtml with some text within.
    Then you should use
    categoryPanel.ContentFromPartial("_Item", item);
    instead of
    categoryPanel.ItemsFromPartial("_Item", item);
    ItemsFromPartial extracts only Ext.NET components from a partial view.
  3. #3
    Hi Daniil, thank you for your suggestion :).

    Actually, my problem is that _Category.cshtml wasn't rendered, otherwise I would see at least some category panels inside the main panel.

    I don't know why but I changed my code from:

    var mainPanel = new Panel().ToBuilder().Title("Category info").Width(800);
    to:

    var mainPanel = X.Html().Panel().Title("Category info").Width(800);
    and it worked!
  4. #4
    Strange, I cannot reproduce. The example below appears to be working for me.

    Main View

    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>
    </head>
    <body>
        @Html.X().ResourceManager()
    
        @{
            var mainPanel = new Panel().ToBuilder().Title("Main Panel").Width(800);
            
            for (int i = 0; i < 5; i++)
            {
                mainPanel.ItemsFromPartial("_Partial");
            }
        }
    
        @mainPanel
    </body>
    </html>
    _Partial.cshml
    @Html.X().Panel().Title("_Partial")

Similar Threads

  1. [CLOSED] Using Razor Partial View on Non-Razor View
    By Patrick_G in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 26, 2013, 4:09 AM
  2. [CLOSED] Issues with a complex layout of many partials
    By ATLAS in forum 2.x Legacy Premium Help
    Replies: 14
    Last Post: Jul 25, 2013, 5:12 AM
  3. how to use localization in an mvc razor view
    By Birgit in forum 2.x Help
    Replies: 1
    Last Post: Mar 21, 2013, 9:32 AM
  4. [CLOSED] MultiHeader for Razor view
    By gets_gui in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 07, 2013, 8:09 PM
  5. Replies: 2
    Last Post: Jan 16, 2012, 9:53 AM

Tags for this Thread

Posting Permissions