Browse Source
Merge pull request #17225 from abpframework/salihozkara/FixDynmicWidgetParamaterProblem
Fix Dynamic Widget Parameter Cast Problem
pull/17239/head
Halil İbrahim Kalkan
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
21 additions and
2 deletions
-
modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml
|
|
|
@ -1,11 +1,13 @@ |
|
|
|
@using System.Dynamic |
|
|
|
@using Microsoft.AspNetCore.Mvc.ViewComponents |
|
|
|
@using Volo.Abp.Data |
|
|
|
@using Volo.Abp.Reflection |
|
|
|
@using Volo.CmsKit.Web.Renderers; |
|
|
|
@using Volo.CmsKit.Web.Pages.CmsKit.Components.Contents; |
|
|
|
|
|
|
|
@model ContentFragmentViewComponent |
|
|
|
|
|
|
|
@inject IMarkdownToHtmlRenderer MarkdownRenderer |
|
|
|
@inject IViewComponentSelector ViewComponentSelector |
|
|
|
|
|
|
|
@foreach (var contentFragment in Model.ContentDto.ContentFragments) |
|
|
|
{ |
|
|
|
@ -15,6 +17,23 @@ |
|
|
|
} |
|
|
|
else if (contentFragment.Type == "Widget") |
|
|
|
{ |
|
|
|
@await Component.InvokeAsync(contentFragment.GetProperty<string>("Type"), contentFragment.ExtraProperties.ConvertToDynamicObject()) |
|
|
|
var componentName = contentFragment.GetProperty<string>("Type"); |
|
|
|
var descriptor = ViewComponentSelector.SelectComponent(componentName); |
|
|
|
var componentParameters = descriptor.Parameters; |
|
|
|
var parameters = new Dictionary<string, object>(contentFragment.ExtraProperties); |
|
|
|
|
|
|
|
foreach (var componentParameter in componentParameters) |
|
|
|
{ |
|
|
|
if (string.IsNullOrWhiteSpace(componentParameter.Name)) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
if(parameters.TryGetValue(componentParameter.Name, out var value)) |
|
|
|
{ |
|
|
|
parameters[componentParameter.Name] = TypeHelper.ConvertFrom(componentParameter.ParameterType, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@await Component.InvokeAsync(componentName, parameters) |
|
|
|
} |
|
|
|
} |