PDA

View Full Version : [CLOSED] Using Razor Partial View on Non-Razor View



Patrick_G
Nov 18, 2013, 8:10 PM
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.

Baidaly
Nov 18, 2013, 9:55 PM
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.

Baidaly
Nov 19, 2013, 1:29 AM
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")
)
)

Patrick_G
Nov 25, 2013, 9:47 PM
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.

Baidaly
Nov 25, 2013, 10:11 PM
Thank you for update!

Daniil
Nov 26, 2013, 4:09 AM
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.