HtmlHelperExtensionsIdenticon Method (IHtmlHelper, Identicon, Int32, String, ExportImageFormat)

Renders an identicon as an IMG tag.
public static IHtmlContent Identicon(
	this IHtmlHelper helper,
	Identicon icon,
	int size = 0,
	string alt = null,
	ExportImageFormat format = ExportImageFormat.Png
)

Parameters

helperIHtmlHelper
The IHtmlHelper.
iconJdenticonIdenticon
The icon that will be rendered.
sizeSystemInt32 (Optional)
The size of the generated icon in pixels. If no size is specified the size of icon will be used.
altSystemString (Optional)
The alt attribute of the rendered image.
formatJdenticonExportImageFormat (Optional)
The file format of the generated icon.

Return Value

IHtmlContent

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IHtmlHelper. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

ExceptionCondition
ArgumentOutOfRangeExceptionsize was less than 1.
ArgumentNullExceptionhelper or icon was null.

Remarks

This extension method can be used in views to insert identicons as <img> tags. The <img> tag will include an url that will be handled by the Jdenticon middleware. Insert a call to UseJdenticon(IApplicationBuilder) right above UseStaticFiles(IApplicationBuilder) to enable the Jdenticon middleware.

Startup.cs
public class Startup
{
    /* ... */

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        /* ... */
        app.UseJdenticon();
        app.UseStaticFiles();
        app.UseMvc();
        /* ... */
    }
}

If you don't need a whole IMG tag, but rather just an url, please have a look at UrlHelperExtensions.

Examples

This example shows how to use the IHtmlHelper extension methods to render identicons as IMG tags.

IHtmlHelper approach
@using Jdenticon.AspNet.Mvc;

<!-- The following markup -->

<div class="user-info">
    @Html.Identicon("JohnDoe64", 60, alt: "JohnDoe64 icon")
    <div class="user-info__name">JohnDoe64</div>
</div>

<!-- is rendered as -->

<div class="user-info">
    <img src="/identicons/5AMA8Xyneag78XyneQ--" width="60" height="60" alt="JohnDoe64 icon" />
    <div class="user-info__name">JohnDoe64</div>
</div>

See Also

Reference