[CLOSED] Using Razor Partial View on Non-Razor View

  1. #1

    [CLOSED] Using Razor Partial View on Non-Razor View

    I am wanting to add some new features to a Non-Razor ASPX page and was wanting to implement it by using a razor partial view (.cshtml). However, whatever combinations I try, the layout is not right.

    In the following example, I want the contents of the partial view to display in the middle panel but it ends up displaying at the top of the page outside of the main page. It is 'somewhat' understandable as the content of the razor view is not in the Items collection of the Panel I want to put them in. Either way, I am wondering if their is a solution or if I was crazy to start with.

    ASPX page
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Panel ID="ViewPort1" runat="server" Layout="VBoxLayout" Height="300" >
                <LayoutConfig>
                    <ext:VBoxLayoutConfig Align="Stretch"></ext:VBoxLayoutConfig>
                </LayoutConfig>
                <Items>             
                    <ext:Panel runat="server" Title="North" Flex="1">                    
                    </ext:Panel>
                    <ext:Panel runat="server" Title="Center" Flex="1" Layout="FitLayout" >
                        <Items>
                            <ext:Container>
                                <Content>
                                    <% Html.RenderPartial("~/Views/Test/TestPartial.cshtml"); %>
                                </Content>
                            </ext:Container>
                        </Items>
                    </ext:Panel>
                    <ext:Panel runat="server" Title="South" Flex="1">
                    </ext:Panel>
                </Items>
            </ext:Panel>
        </form>
    </body>
    </html>
    TestPartial.cshtml
    @(
     Html.X().Panel().Height(300).Title("TOP PANEL in Partial View")
            .Layout(LayoutType.VBox)
            .LayoutConfig(new VBoxLayoutConfig { Align = VBoxAlign.Stretch })
            .Items(
                Html.X().Panel().Flex(1).Title("FIRST PANEL"),
                Html.X().Panel().Flex(1).Title("SECOND PANEL")
            )
    )
    Thank you for your help.
    Last edited by Daniil; Nov 22, 2013 at 4:12 AM. Reason: [CLOSED]
  2. #2
    Hello!

    I guess the problem is that you load it inside Content property which I guess doesn't use layout to render children. However, we will investigate it.
  3. #3
    OK, I got it. According to this sample: http://mvc.ext.net/#/Items/ASPX_Engine/ you should use the following markup:
    ASPX page:
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
    </head>
    <body>
        <form id="Form1" runat="server"> 
            <ext:ResourceManager ID="ResourceManager1" runat="server" SourceFormatting="true" />
            <ext:Panel ID="ViewPort1" runat="server" Layout="VBoxLayout" Height="300" >
                <LayoutConfig>
                    <ext:VBoxLayoutConfig Align="Stretch"></ext:VBoxLayoutConfig>
                </LayoutConfig>
                <Items>             
                    <ext:Panel ID="Panel1" runat="server" Title="North" Flex="1">                    
                    </ext:Panel>
                    <ext:Panel ID="Panel2" runat="server" Title="Center" Flex="1" Layout="FitLayout" >
                        <Items>
                            <ext:Container runat="server">
                                <Content>
                                     <%= Html.ExtPartial("PartialView") %>
                                </Content>
                            </ext:Container>
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="Panel3" runat="server" Title="South" Flex="1">
                    </ext:Panel>
                </Items>
            </ext:Panel>
        </form>
    </body>
    </html>
    PartialView.cshtml
    @(
     Html.X().Panel().Height(300).Title("TOP PANEL in Partial View")
            .Layout(LayoutType.VBox)
            .LayoutConfig(new VBoxLayoutConfig { Align = VBoxAlign.Stretch })
            .Items(
                Html.X().Panel().Flex(1).Title("FIRST PANEL"),
                Html.X().Panel().Flex(1).Title("SECOND PANEL")
            )
    )
    Last edited by Baidaly; Nov 19, 2013 at 1:43 AM.
  4. #4
    Thank you Baidaly, your suggestion worked perfectly. You guys thought of everything. One thing to note, for some reason I could not get
    <%= Html.ExtPartial("PartialView") %>
    to work
    but the following did work
    <%= Html.Partial("PartialView") %>
    Thank you again for all your help.
  5. #5
    Thank you for update!
  6. #6
    Quote Originally Posted by Patrick_G View Post
    Thank you Baidaly, your suggestion worked perfectly. You guys thought of everything. One thing to note, for some reason I could not get
    <%= Html.ExtPartial("PartialView") %>
    to work
    If you can provide us with a test case, we would be happy to investigate.

Similar Threads

  1. 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
  2. [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
  3. Replies: 4
    Last Post: Apr 09, 2012, 2:10 PM
  4. [CLOSED] Razor syntax for adding a partial view to a Panel
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 23, 2012, 9:55 AM
  5. Replies: 2
    Last Post: Jan 16, 2012, 9:53 AM

Tags for this Thread

Posting Permissions