PDA

View Full Version : [Razor] How to add items to a Panel from a Partial View



jxlarrea
Apr 04, 2012, 11:07 PM
It is possible to add items to a Panel from a Partial View? Something like this:



@(Html.X().Viewport()
.Layout(LayoutType.Border)
.Resizable(true)
.Split(true)

.Items(items =>
{

items.Add(Html.X().Panel().Title("Hola").Region(Region.West).Resizable(true).Width(200));
items.Add(Html.X().Panel().Title("Chao").Region(Region.Center).Items(items2 =>
{

Html.RenderPartial("_MyPartialView");


}));

})

)


It's certainly possible to add a UserControl as a Panel <content> using the ASPX engine but I can't figure out how to achieve it using Razor.

Thanks.

Daniil
Apr 05, 2012, 3:08 PM
Hi,

Please use the ItemsFromPage property.

.ItemsFromPage(this, "viewName.cshtml")

jxlarrea
Apr 09, 2012, 3:05 PM
Thank you, worked perfectly although there is a strange behavior. The GridPanel loaded from the partial view won't anchor 100% to the center region specified in the Viewport (It grows the size of the items on the grid and overflows offscreen). I'm not sure how to accomplish this. I'm also suspecting that the "Booking" panel has something to do with the problem.

Index.cshtml


@Html.X().ResourceManager()

@(Html.X().Viewport()
.Layout(LayoutType.Border)
.Split(true)
.Items(items =>
{
items.Add(Html.X().Panel().Title("Options").Region(Region.West).Width(200));
items.Add(Html.X().Panel().Title("Booking").Region(Region.Center).ItemsFromPage(this,"~/Views/Shared/_BookingGrid.cshtml"));
})


)


_BookingGrid.cshtml

@(Html.X().GridPanel()
.Store(store => store.Add(Html.X().Store()
.AutoLoad(true)
.Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
.Url("/Data/GetShips/")
.Reader(reader => reader.Add(Html.X().JsonReader()
.Root("result")
))
))
.Model(model => model.Add(Html.X().Model()
.Fields(fields =>
{
fields.Add(Html.X().ModelField().Name("Name"));
fields.Add(Html.X().ModelField().Name("Code"));
})
))
))


.ColumnModel(columnModel =>
{

columnModel.Columns.Add(Html.X().Column()
.Text("Code")
.DataIndex("Code")
.Width(70));
columnModel.Columns.Add(Html.X().Column()
.Text("Name")
.DataIndex("Name")
.Flex(1));
})

.BottomBar(bottomBar => bottomBar.Add(Html.X().PagingToolbar()))


)

Vladimir
Apr 09, 2012, 3:09 PM
Please set fit layout for center region panel (panel with title 'Booking')

jxlarrea
Apr 09, 2012, 3:10 PM
Nevermind, found the problem. I had to add .Layout(LayoutType.Fit) to the "Booking" Panel.

Thanks for your help regarding the initial problem!