postal icon indicating copy to clipboard operation
postal copied to clipboard

Style attribute for embedded image

Open denisz1 opened this issue 9 years ago • 4 comments

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?

denisz1 avatar Feb 27 '15 05:02 denisz1

I've added a PR.

denisz1 avatar Feb 27 '15 20:02 denisz1

upvote

ghost avatar Mar 25 '15 13:03 ghost

+1

jnis77diver avatar Sep 22 '16 11:09 jnis77diver

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")

jeffreyharris avatar Apr 02 '17 18:04 jeffreyharris