Ejemplo n.º 1
0
        /// <summary>
        /// 建立排序標題
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="actionName">Action方法</param>
        /// <param name="query">查詢參數</param>
        /// <param name="propertyName">屬性名稱</param>
        /// <param name="displayName">顯示名稱</param>
        /// <returns></returns>
        public static MvcHtmlString BuildSortLink(this HtmlHelper helper,
                                                  string actionName, QueryOption query, string propertyName, string displayName)
        {
            var urlHelper      = new UrlHelper(helper.ViewContext.RequestContext);
            var isCurrentField = propertyName == query.SortField;

            StringBuilder classBuilder = new StringBuilder("glyphicon glyphicon-sort");

            if (isCurrentField)
            {
                classBuilder.Append("-by-alphabet");
                if (query.SortOrder == SortOrder.DESC)
                {
                    classBuilder.Append("-alt");
                }
            }

            var outputQuery = query.Clone();

            outputQuery.SortField = propertyName;
            outputQuery.SortOrder = query.SortOrder == SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;

            return(new MvcHtmlString(
                       $"<a href=\"{urlHelper.Action(actionName, outputQuery)}\">" +
                       $"{displayName} <span class=\"{classBuilder}\"></span>" +
                       "</a>"));
        }
Ejemplo n.º 2
0
        public static QueryOption Page(this QueryOption queryOption, int page)
        {
            var option = queryOption.Clone();

            option.CurrentPage = page;
            return(option);
        }