网站首页 网站源码
website
站点相关全部源代码,隐藏了一些关于服务器的信息
@using Microsoft.AspNetCore.WebUtilities
@using Microsoft.Extensions.Primitives
@model (List<string> Categories, IReadOnlyCollection<string> SelectedCategories)

<div class="category-box">
    @foreach (var item in Model.Categories)
    {
        if (Model.SelectedCategories.Contains(item))
        {
            var dic = QueryHelpers.ParseQuery(Context.Request.QueryString.Value);
            if (dic.ContainsKey("categories"))
            {
                var removeValues = dic["categories"].Where(x => x != item).ToArray();
                if (removeValues.Any())
                {
                    var query = new StringValues(removeValues);
                    dic["categories"] = query;
                }
                else
                {
                    dic.Remove("categories");
                }
            }

            if (dic.ContainsKey("_pjax"))
            {
                dic.Remove("_pjax");
            }

            var url = QueryHelpers.AddQueryString(Context.Request.Path, dic);
            <a href="@url" class="category active">@item</a>
        }
        else
        {
            var dic = QueryHelpers.ParseQuery(Context.Request.QueryString.Value);
            if (dic.ContainsKey("categories"))
            {
                var parameters = dic["categories"].ToList();
                parameters.Add(item);
                dic["categories"] = parameters.ToArray();
            }
            else
            {
                dic.Add("categories", item);
            }

            if (dic.ContainsKey("_pjax"))
            {
                dic.Remove("_pjax");
            }

            var url = QueryHelpers.AddQueryString(Context.Request.Path, dic);
            <a href="@url" class="category">@item</a>
        }
    }
</div>
loading