Render grid partials async

This commit is contained in:
Bjarne Fyrstenborg
2021-06-22 19:33:48 +02:00
parent c41d05f6a6
commit ff65a333e1
2 changed files with 36 additions and 22 deletions

View File

@@ -39,38 +39,45 @@
</div>
}
@functions {
private void renderRow(dynamic row)
@functions{
private async Task renderRow(dynamic row)
{
<div @RenderElementAttributes(row)>
<div class="row clearfix">
@foreach ( var area in row.areas ) {
@foreach (var area in row.areas)
{
<div class="col-md-@area.grid column">
<div @RenderElementAttributes(area)>
@foreach (var control in area.controls) {
if (control !=null && control.editor != null && control.editor.view != null ) {
<text>@Html.Partial("grid/editors/base", (object)control)</text>
@foreach (var control in area.controls)
{
if (control != null && control.editor != null && control.editor.view != null ) {
<text>@await Html.PartialAsync("grid/editors/base", (object)control)</text>
}
}
</div>
</div>}
</div>
}
</div>
</div>
}
}
@functions {
@functions{
public static HtmlString RenderElementAttributes(dynamic contentItem)
{
var attrs = new List<string>();
JObject cfg = contentItem.config;
if(cfg != null)
if (cfg != null)
{
foreach (JProperty property in cfg.Properties())
{
var propertyValue = HttpUtility.HtmlAttributeEncode(property.Value.ToString());
attrs.Add(property.Name + "=\"" + propertyValue + "\"");
}
}
JObject style = contentItem.styles;

View File

@@ -21,10 +21,10 @@
}else {
<div class="container">
<div class="row clearfix">
@foreach (var s in Model.sections) {
@foreach (var sec in Model.sections) {
<div class="grid-section">
<div class="col-md-@s.grid column">
@foreach (var row in s.rows)
<div class="col-md-@sec.grid column">
@foreach (var row in sec.rows)
{
renderRow(row, false);
}
@@ -37,25 +37,29 @@
</div>
}
@functions {
@functions{
private void renderRow(dynamic row, bool singleColumn)
private async Task renderRow(dynamic row, bool singleColumn)
{
<div @RenderElementAttributes(row)>
@if (singleColumn) {
@:<div class="container">
}
<div class="row clearfix">
@foreach ( var area in row.areas ) {
@foreach (var area in row.areas)
{
<div class="col-md-@area.grid column">
<div @RenderElementAttributes(area)>
@foreach (var control in area.controls) {
if (control !=null && control.editor != null && control.editor.view != null ) {
<text>@Html.Partial("grid/editors/base", (object)control)</text>
@foreach (var control in area.controls)
{
if (control != null && control.editor != null && control.editor.view != null)
{
<text>@await Html.PartialAsync("grid/editors/base", (object)control)</text>
}
}
</div>
</div>}
</div>
}
</div>
@if (singleColumn) {
@:</div>
@@ -65,23 +69,26 @@
}
@functions{
@functions {
public static HtmlString RenderElementAttributes(dynamic contentItem)
{
var attrs = new List<string>();
JObject cfg = contentItem.config;
if(cfg != null)
if (cfg != null)
{
foreach (JProperty property in cfg.Properties())
{
var propertyValue = HttpUtility.HtmlAttributeEncode(property.Value.ToString());
attrs.Add(property.Name + "=\"" + propertyValue + "\"");
}
}
JObject style = contentItem.styles;
if (style != null) {
if (style != null)
{
var cssVals = new List<string>();
foreach (JProperty property in style.Properties())
{