New to Telerik UI for ASP.NET MVC? Download free 30-day trial

Getting Started with the Avatar

This tutorial explains how to set up a basic Telerik UI for ASP.NET MVC Avatar and highlights the major steps in the configuration of the component.

You will initialize an Avatar component with different appearance-related options.

Sample Telerik UI for ASP.NET MVC Avatar

Prerequisites

To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET MVC components:

1. Prepare the CSHTML File

The first step is to add the required directives at the top of the .cshtml document:

  • To use the Telerik UI for ASP.NET MVC HtmlHelpers:

    @using Kendo.Mvc.UI
    

Optionally, you can structure the View content by adding the desired HTML elements like headings, divs, paragraphs, and others.

    @using Kendo.Mvc.UI

    <div id="avatar-container">

    </div>

2. Initialize the Avatar

Use the Avatar HtmlHelper to add the component to a page:

  • The Name() configuration method is mandatory as its value is used for the id and the name attributes of the Avatar element.
  • The Type() option specifies the type of the Avatar.
  • The Text() defines the text that will be displayed in the Avatar, when the Type option is set to AvatarType.Text.
  • The Image() specifies the URL of the image that will be displayed in the Avatar, when the Type option is AvatarType.Image.
  • The Icon() sets the name of the icon that will be displayed in the Avatar, when the Type is AvatarType.Icon.
  • The Rounded() option defines the component shape.
    @using Kendo.Mvc.UI

    <div id="avatar-container">
        @(Html.Kendo().Avatar()
            .Name("avatar")
            .Type(AvatarType.Image)
            .Rounded(Rounded.Full)
            .Image("https://demos.telerik.com/aspnet-core/shared/web/Customers/FAMIA.jpg")
        )
    </div>

3. Customize the Appearance of the Avatar

The configuration options like Size, FillMode, Border, Rounded, and more allow you to control the appearance of the Avatar component.

    @using Kendo.Mvc.UI

    <div id="avatar-container">
        @(Html.Kendo().Avatar()
            .Name("avatar")
            .Type(AvatarType.Image)
            .Size(ComponentSize.Large)
            .FillMode(AvatarFillMode.Outline)
            .Rounded(Rounded.Large)
            .Border(true)
            .Image("https://demos.telerik.com/aspnet-core/shared/web/Customers/FAMIA.jpg")
        )
    </div>

4. (Optional) Reference Existing Avatar Instances

You can reference the Avatar instances that you have created and build on top of their existing configuration. Use the Name() value of the component to get its reference.

    @(Html.Kendo().Avatar()
        .Name("avatar")
        .Type(AvatarType.Image)
        .Rounded(Rounded.Full)
        .Image("https://demos.telerik.com/aspnet-core/shared/web/Customers/FAMIA.jpg")
    )
    <script>
        $(document).ready(function() {
            var avatar = $("#avatar").data("kendoAvatar"); // The `avatar` variable holds a reference to the existing Avatar instance of the helper.
        });
    </script>

For more information on referencing specific helper instances, see the Methods and Events article.

Next Steps

See Also

In this article