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

Getting Started with the Avatar

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

You will initialize an Avatar component with different appearance-related options. Finally, you can run the sample code in Telerik REPL and continue exploring the components.

Sample Telerik UI for ASP.NET Core Avatar

Prerequisites

To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET Core 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 Core HtmlHelpers:

    @using Kendo.Mvc.UI
    
  • To use the Telerik UI for ASP.NET Core TagHelpers:

    @addTagHelper *, Kendo.Mvc
    

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>
    @addTagHelper *, Kendo.Mvc

    <div id="avatar-container">

    </div>

2. Initialize the Avatar

Use the Avatar HtmlHelper or TagHelper 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>
    @addTagHelper *, Kendo.Mvc

    <div id="avatar-container">
        <kendo-avatar name="avatar"
            type="AvatarType.Image"
            rounded="Rounded.Full"
            image="https://demos.telerik.com/aspnet-core/shared/web/Customers/FAMIA.jpg">
        </kendo-avatar>
    </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>
    @addTagHelper *, Kendo.Mvc

    <div id="avatar-container">
        <kendo-avatar name="avatar"
            type="AvatarType.Image"
            size="ComponentSize.Large"
            fill-mode="AvatarFillMode.Outline"
            border="true"
            rounded="Rounded.Large"
            image="https://demos.telerik.com/aspnet-core/shared/web/Customers/FAMIA.jpg">
        </kendo-avatar>
    </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")
    )
    @addTagHelper *, Kendo.Mvc

    <kendo-avatar name="avatar"
        type="AvatarType.Image"
        rounded="Rounded.Full"
        image="https://demos.telerik.com/aspnet-core/shared/web/Customers/FAMIA.jpg">
    </kendo-avatar>
    <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.

Explore this Tutorial in REPL

You can continue experimenting with the code sample above by running it in the Telerik REPL server playground:

Next Steps

See Also

In this article