Q:

Output of certain strings

There is a code in Homepage which output strings from database:
@foreach (var post in Model.Posts)
    {
        <a asp-controller="Home" asp-action="Post" asp-route-id="@post.Id" >
            <span class="title">
                @post.Title,
                @post.Body,
                @post.Category
            </span>
        </a>
    }

All strings are output correctly. Each string has some variables (in table dbo.Posts and Models file Post.cs)
public string Title { get; set; } = "";
public string Body { get; set; } = "";
public string Category { get; set; } = "";

I would like that program could output on the page in table only strings consist certain value of variable "Category" and in other case string isn't output. How is it possible?

A:

Filter your Posts collection server-side before sending it to view. For example:
viewModel.Posts = GetPosts().Where(p => p.Category == "certain value");

