Ridiculously simple Gravatar integration for Asp.Net MVC: @Html.GravatarImage("user.name@email.com")
C#
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
GravatarHtmlHelper_Net35.cs Added class (cssClass) and alt attribute overrides Jan 7, 2017
GravatarHtmlHelper_Net40.cs
GravatarHtmlHelper_NetCore.cs Added class (cssClass) and alt attribute overrides Jan 7, 2017
README.md Added class (cssClass) and alt attribute overrides Jan 7, 2017

README.md

Gravatar HtmlHelper for ASP.Net MVC

This is a complete implementation of the Gravatar image request API, according the Gravatar documentation, as an ASP.Net MVC HtmlHelper.

Features

  • Size
  • Default image (404, mystery-man, identicon, monsterid, wavatar, retro)
  • Custom default image (url)
  • Force default image
  • Ratings
  • Secure requests (HTTPS) is automatic (but can be forced)
  • Named and Optional Arguments for .Net 4.0 and above
  • Custom CSS class attribute string (cssClass)
  • Custom alt attribute string alt)

Getting Started

  1. Drop the GravatarHtmlHelper_{version}.cs file anywhere in your ASP.Net MVC project:

    GravatarHtmlHelper_NetCore.cs 🆕
    for .Net Core / ASP.Net Core MVC

    GravatarHtmlHelper_Net40.cs
    for .Net 4.0+ / ASP.Net MVC 3, 4, 5+

    GravatarHtmlHelper_Net35.cs
    for .Net 3.5 / ASP.Net MVC 2.0

  2. Recompile and start using it in your Views:

@Html.GravatarImage("user.name@email.com")
@Html.GravatarImage(
  "user.name@email.com",
  size: 32,
  defaultImage: GravatarHtmlHelper.DefaultImage.Identicon,
  rating: GravatarHtmlHelper.Rating.PG,
  cssClass: "gravatar img-responsive")

That's it. No attribution required, but feel free to leave a comment on my blog if you find it useful

Alternatives

Mark Mailer has a TagHelper implementation for ASP.Net Core MVC