public static IHtmlContent Identicon( this IHtmlHelper helper, Identicon icon, int size = 0, string alt = null, ExportImageFormat format = ExportImageFormat.Png )
Exception | Condition |
---|---|
ArgumentOutOfRangeException | size was less than 1. |
ArgumentNullException | helper or icon was null. |
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.
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.
This example shows how to use the IHtmlHelper extension methods to render identicons as IMG tags.
@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>