How to do it...

View components let developers create a component with both server-side logic and client-side code to render layout.

  1. First, add a service and a TagCloud class in order to display a list of tag clouds in a reusable component:
public interface ITagCloudService 
{ 
  Task<List<Tag>> GetTagsAsync(string userBlog); 
} 
 
public class TagCloudService : ITagCloudService 
{ 
  public async Task<List<Tag>> GetTagsAsync(string userBlog) 
  { 
    return await Task.Run(() => GetTags(userBlog)); 
  } 
 
  private List<Tag> GetTags(string userBlog) 
  { 
    return new List<Tag> 
    { 
      new Tag { Id = 1, Name = "Asp.Net Core" }, 
      new Tag { Id = 2, Name = "EF Core" } 
    }; 
  } 
} 
 
public class Tag 
{ 
  public int Id { get; set; } 
  public string Name { get; set; } 
} 
  1. In Sartup.cs, we configure ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.