From f090da2057cdcfa1348c4740c1d4caf7fe0ee960 Mon Sep 17 00:00:00 2001 From: akdalin Date: Tue, 11 Mar 2025 09:53:03 +0000 Subject: [PATCH 1/2] Create InsetText View, ViewComponent and Model --- .../ViewComponents/InsetTextViewComponent.cs | 18 ++++++++++++++++++ .../ViewModels/InsetTextViewModel.cs | 15 +++++++++++++++ .../Shared/Components/InsetText/Default.cshtml | 7 +++++++ 3 files changed, 40 insertions(+) create mode 100644 DotnetViewComponents/ViewComponents/InsetTextViewComponent.cs create mode 100644 DotnetViewComponents/ViewModels/InsetTextViewModel.cs create mode 100644 DotnetViewComponents/Views/Shared/Components/InsetText/Default.cshtml diff --git a/DotnetViewComponents/ViewComponents/InsetTextViewComponent.cs b/DotnetViewComponents/ViewComponents/InsetTextViewComponent.cs new file mode 100644 index 0000000000..cf1ccab57b --- /dev/null +++ b/DotnetViewComponents/ViewComponents/InsetTextViewComponent.cs @@ -0,0 +1,18 @@ +namespace DotnetViewComponents.ViewComponents +{ + using System.Collections.Generic; + using Microsoft.AspNetCore.Mvc; + using DotnetViewComponents.ViewModels; + + public class InsetTextViewComponent : ViewComponent + { + public IViewComponentResult Invoke( + string text, + string cssClass = null + ) + { + var model = new InsetTextViewModel(text, string.IsNullOrEmpty(cssClass) ? null : cssClass); + return View(model); + } + } +} diff --git a/DotnetViewComponents/ViewModels/InsetTextViewModel.cs b/DotnetViewComponents/ViewModels/InsetTextViewModel.cs new file mode 100644 index 0000000000..d4fd1531ef --- /dev/null +++ b/DotnetViewComponents/ViewModels/InsetTextViewModel.cs @@ -0,0 +1,15 @@ +namespace DotnetViewComponents.ViewModels +{ + public class InsetTextViewModel + { + public InsetTextViewModel(string text, string? cssClass = null) + { + Text = text; + CssClass = cssClass; + } + + public string Text { get; set; } + + public string? CssClass { get; set; } + } +} diff --git a/DotnetViewComponents/Views/Shared/Components/InsetText/Default.cshtml b/DotnetViewComponents/Views/Shared/Components/InsetText/Default.cshtml new file mode 100644 index 0000000000..ae0a6caefd --- /dev/null +++ b/DotnetViewComponents/Views/Shared/Components/InsetText/Default.cshtml @@ -0,0 +1,7 @@ +@using DotnetViewComponents.ViewModels +@model InsetTextViewModel + +
+ Information: +

@Html.Raw(Model.Text)

+
From 3adab8f3dcf72966b64fef3eacca04d746d3d934 Mon Sep 17 00:00:00 2001 From: akdalin Date: Thu, 24 Apr 2025 11:58:23 +0100 Subject: [PATCH 2/2] Rename Text to ContentHtml. Remove ClassCSS parameter. --- .../ViewComponents/InsetTextViewComponent.cs | 8 ++------ DotnetViewComponents/ViewModels/InsetTextViewModel.cs | 9 +++------ .../Views/Shared/Components/InsetText/Default.cshtml | 4 ++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/DotnetViewComponents/ViewComponents/InsetTextViewComponent.cs b/DotnetViewComponents/ViewComponents/InsetTextViewComponent.cs index cf1ccab57b..6601fcf6c8 100644 --- a/DotnetViewComponents/ViewComponents/InsetTextViewComponent.cs +++ b/DotnetViewComponents/ViewComponents/InsetTextViewComponent.cs @@ -1,17 +1,13 @@ namespace DotnetViewComponents.ViewComponents { - using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using DotnetViewComponents.ViewModels; public class InsetTextViewComponent : ViewComponent { - public IViewComponentResult Invoke( - string text, - string cssClass = null - ) + public IViewComponentResult Invoke(string contentHtml) { - var model = new InsetTextViewModel(text, string.IsNullOrEmpty(cssClass) ? null : cssClass); + var model = new InsetTextViewModel(contentHtml); return View(model); } } diff --git a/DotnetViewComponents/ViewModels/InsetTextViewModel.cs b/DotnetViewComponents/ViewModels/InsetTextViewModel.cs index d4fd1531ef..e876077a9c 100644 --- a/DotnetViewComponents/ViewModels/InsetTextViewModel.cs +++ b/DotnetViewComponents/ViewModels/InsetTextViewModel.cs @@ -2,14 +2,11 @@ namespace DotnetViewComponents.ViewModels { public class InsetTextViewModel { - public InsetTextViewModel(string text, string? cssClass = null) + public InsetTextViewModel(string contentHtml) { - Text = text; - CssClass = cssClass; + ContentHtml = contentHtml; } - public string Text { get; set; } - - public string? CssClass { get; set; } + public string ContentHtml { get; set; } } } diff --git a/DotnetViewComponents/Views/Shared/Components/InsetText/Default.cshtml b/DotnetViewComponents/Views/Shared/Components/InsetText/Default.cshtml index ae0a6caefd..22d871dd63 100644 --- a/DotnetViewComponents/Views/Shared/Components/InsetText/Default.cshtml +++ b/DotnetViewComponents/Views/Shared/Components/InsetText/Default.cshtml @@ -1,7 +1,7 @@ @using DotnetViewComponents.ViewModels @model InsetTextViewModel -
+
Information: -

@Html.Raw(Model.Text)

+

@Html.Raw(Model.ContentHtml)