I would like to display tags as a list of items rather than a count.

Details.cshtml

<div class="display-label">Tags</div>
<div class="display-field">@(Model.Tags == null ? "None" : Model.Tags.Count.ToString())</div>

Post.cs

public class Post
{
    public int PostId { get; set; }

    public string Title { get; set; }
    public string Body { get; set; }
    public DateTime CreatedAt { get; set; }
    public virtual ICollection<Tag> Tags { get; set; } 
}

Tag.cs

public class Tag
{

        public int TagId { get; set; }
        public string Name { get; set; }

        // Relationship with Post
        public int PostId { get; set; }
        public virtual Post Post { get; set; } // This is new

}

I tried List, Ilist, Enumerable in the Details.cshtml view file. I want to display the list of Tags as strings for each post.

Related posts

Recent Viewed