postal
postal copied to clipboard
Style attribute for embedded image
When styling emails, it is necessary to use inline styles in the style
attribute, because webmail services (gmail and friends) strip out stylesheets.
The @Html.EmbedImage
extension method can render the alt
attribute, but not a style
attribute. So I can't style my images.
The signature could be changed from:
public static IHtmlString EmbedImage(this HtmlHelper html, string imagePathOrUrl, string alt = "")
to:
public static IHtmlString EmbedImage(this HtmlHelper html, string imagePathOrUrl, string alt = "", string style= "")
And the final line from:
return new HtmlString(string.Format("<img src=\"cid:{0}\" alt=\"{1}\"/>", linkedResource.ContentId, html.AttributeEncode(alt)));
to:
return new HtmlString(string.Format("<img src=\"cid:{0}\" alt=\"{1}\" style="{2}"/>", linkedResource.ContentId, html.AttributeEncode(alt), html.AttributeEncode(style)));
What do you think?
I've added a PR.
upvote
+1
Can someone tell me the syntax for the @HTML embed image tag with styles applied? For example, how would you add styles to this:
@Html.EmbedImage("~/Content/graphics/global/logo.png")