PDA

View Full Version : [CLOSED] MVC Razor ContentFromSection



Timothy
Apr 30, 2012, 7:18 PM
Hello,

Just curious how to use the ContentFromSection, or ContentFromPage on a Panel in MVC 3 Razor?

I've got the following:



@(Html.X().Viewport()
.Border(false)
.Layout(Ext.Net.LayoutType.Fit)
.Items(a =>
a.Add(Html.X().Panel()
.Border(false)
.ContentFromSection( ... )
)
)
)




I noticed the first parameter is of WebPageBase.

Any example appreciated :)

Cheers

Daniil
Apr 30, 2012, 7:33 PM
Hi,

Here you are.

ItemsFromSection Example

Example Layout View

<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
</head>
<body>
@Html.X().ResourceManager()

@(Html.X().Panel()
.Title("Panel1")
.Width(400)
.Height(400)
.Icon(Icon.Add)
.Layout(LayoutType.Accordion)
.ItemsFromSection(this, "section1")
)

@(Html.X().Panel()
.Title("Panel2")
.Width(400)
.Height(400)
.Icon(Icon.Application)
.Layout(LayoutType.Accordion)
.ItemsFromSection(this, "section2")
)
</body>
</html>

Example View (which used the layout view above)

@{
ViewBag.Title = "ItemsFromSection";
Layout = "~/Views/Test/LayoutSection.cshtml";
}

@section section1{
@(Html.X().Panel()
.Title("Section 1 - Panel 1")
.Height(150)
.Icon(Icon.BulletPlus)
)

@(Html.X().Panel()
.Title("Section 1 - Panel 2")
.Height(150)
.Icon(Icon.BulletMinus)
)

@(Html.X().Panel()
.Title("Section 1 - Panel 3")
.Height(150)
.Icon(Icon.BulletStar)
)
}


@section section2{
@(Html.X().Panel()
.Title("Section 2 - Panel 1")
.Height(150)
.Icon(Icon.BulletPlus)
)

@(Html.X().Panel()
.Title("Section 2 - Panel 2")
.Height(150)
.Icon(Icon.BulletMinus)
)

@(Html.X().Panel()
.Title("Section 2 - Panel 3")
.Height(150)
.Icon(Icon.BulletStar)
)
}

Daniil
Apr 30, 2012, 7:35 PM
ItemsFromPage Example

Example View

@{
Layout = "";
}
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
</head>
<body>
@Html.X().ResourceManager().Theme(Theme.Gray)

<h1>Panel 2</h1>

@(
Html.X().Panel()
.Title("Panel 1")
.Width(400)
.Height(400)
.Icon(Icon.Add)
.Layout(LayoutType.Accordion)
.ItemsFromPage(this, "~/Views/Test/SubPage.cshtml")
)

<h1>Panel 2</h1>

@(
Html.X().Panel()
.Title("Panel 2")
.Width(400)
.Height(400 )
.Icon(Icon.Application)
.Layout(LayoutType.Accordion)
.ItemsFromPage(this, "~/Views/Test/SubPage.cshtml")
)
</body>
</html>


Example Child View (SubPage.cshtml)

@(Html.X()
.Panel()
.Title("SubPage - Panel 1")
.Height(150)
.Icon(Icon.BulletPlus)
)

@(Html.X()
.Panel()
.Title("SubPage - Panel 2")
.Height(150)
.Icon(Icon.BulletMinus)
)

@(Html.X()
.Panel()
.Title("SubPage - Panel 3")
.Height(150)
.Icon(Icon.BulletStar)
)

Timothy
Apr 30, 2012, 7:54 PM
Great examples, thank you very much for your time!

Cheers,
Timothy

Daniil
Apr 30, 2012, 7:57 PM
These examples have been already done by Vladimir :) I just posted them.

They should be available for all soon.

edip
Apr 29, 2016, 5:43 PM
I found my issue again...razor can be very problematic...there was a space between my
@Html.X ( )
"Html.X" and the opening bracket. Why can't razor parse out a space?...it is parsing c#?

Thanks.

geoffrey.mcgill
Apr 29, 2016, 6:12 PM
Hello @edip,

It would be best to start a new thread.