From 6ed55fb118057ec0315ddc2aa4a36ed8577da41b Mon Sep 17 00:00:00 2001 From: Valdis Iljuconoks Date: Mon, 23 Nov 2020 09:41:05 +0200 Subject: [PATCH] Closes #43 --- samples/SampleAlloy/Views/StartPage/Index.cshtml | 5 +++++ .../HtmlHelperExtensionsForPicture.cs | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/samples/SampleAlloy/Views/StartPage/Index.cshtml b/samples/SampleAlloy/Views/StartPage/Index.cshtml index 2b74f1b..6464bda 100644 --- a/samples/SampleAlloy/Views/StartPage/Index.cshtml +++ b/samples/SampleAlloy/Views/StartPage/Index.cshtml @@ -4,6 +4,11 @@ @model PageViewModel +
+ @Html.Raw(Html.ResizePicture(Model.CurrentPage.MainImage, PictureProfiles.SampleImage, cssClass: "sample-css-class").ToHtmlString()) + @Html.ResizePicture(Model.CurrentPage.MainImage, PictureProfiles.SampleImage, cssClass: "sample-css-class") +
+
@Html.ResizePictures(new[] { diff --git a/src/ImageResizer.Plugins.EPiServerBlobReader/HtmlHelperExtensionsForPicture.cs b/src/ImageResizer.Plugins.EPiServerBlobReader/HtmlHelperExtensionsForPicture.cs index 143491e..bd0bbd7 100644 --- a/src/ImageResizer.Plugins.EPiServerBlobReader/HtmlHelperExtensionsForPicture.cs +++ b/src/ImageResizer.Plugins.EPiServerBlobReader/HtmlHelperExtensionsForPicture.cs @@ -39,7 +39,7 @@ public static MvcHtmlString ResizePictures(this HtmlHelper helper, UrlBuilder[] source.Attributes.Add("srcset", url.ToString()); source.Attributes.Add("media", media); - sources.Append(source); + sources.Append(source.ToString(TagRenderMode.SelfClosing)); } var img = new TagBuilder("img"); @@ -50,7 +50,7 @@ public static MvcHtmlString ResizePictures(this HtmlHelper helper, UrlBuilder[] if (!string.IsNullOrEmpty(cssClass)) img.Attributes.Add("class", cssClass); - picture.InnerHtml = sources.ToString() + img; + picture.InnerHtml = sources + img.ToString(TagRenderMode.SelfClosing); return new MvcHtmlString(picture.ToString()); } @@ -88,7 +88,7 @@ public static MvcHtmlString ResizePicture(this HtmlHelper helper, UrlBuilder url public static MvcHtmlString ResizePicture(this HtmlHelper helper, ContentReference image, PictureProfile profile, string alternateText = "", string cssClass = "") { var imgUrl = helper.ResizeImage(image, profile.DefaultWidth); - var sourceSets = profile.SrcSetWidths.Select(w => $"{helper.ResizeImage(image, w).ToString()} {w}w").ToArray(); + var sourceSets = profile.SrcSetWidths.Select(w => $"{helper.ResizeImage(image, w)} {w}w").ToArray(); return GeneratePictureElement(profile, imgUrl.ToString(), sourceSets, alternateText, cssClass); } @@ -109,7 +109,7 @@ private static MvcHtmlString GeneratePictureElement(PictureProfile profile, stri if(!string.IsNullOrEmpty(cssClass)) img.Attributes.Add("class", cssClass); - picture.InnerHtml = source.ToString() + img; + picture.InnerHtml = source.ToString(TagRenderMode.SelfClosing) + img.ToString(TagRenderMode.SelfClosing); return new MvcHtmlString(picture.ToString()); }