private void RenderButtons(NavHtmlTextWritter textWriter)
        {
            // Buttons Control-Group
            textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "form-group");
            textWriter.RenderBeginTag((HtmlTextWriterTag)HtmlTextWriterTag.Div);

            // Controls Div
            textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "controls");
            textWriter.RenderBeginTag((HtmlTextWriterTag)HtmlTextWriterTag.Div);

            // Submit Button
            textWriter.AddAttribute(HtmlTextWriterAttribute.Type, "submit");
            textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "btn btn-default btn-primary");
            textWriter.AddAttribute(HtmlTextWriterAttribute.Value, "Submit");
            textWriter.RenderBeginTag((HtmlTextWriterTag)HtmlTextWriterTag.Input);
            textWriter.RenderEndTag(); //</input>

            textWriter.Write("&nbsp;&nbsp;");

            // Cancel Button
            textWriter.AddAttribute(HtmlTextWriterAttribute.Type, "button");
            textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "btn btn-default");
            textWriter.AddAttribute(HtmlTextWriterAttribute.Value, "Cancel");
            textWriter.AddAttribute(HtmlTextWriterAttribute.Onclick,
                                    "window.location = '" + helper.ViewContext.HttpContext.Request.UrlReferrer + "'");
            textWriter.RenderBeginTag((HtmlTextWriterTag)HtmlTextWriterTag.Input);
            textWriter.RenderEndTag(); //</input>

            textWriter.RenderEndTag(); // div (Controls Div)

            textWriter.RenderEndTag(); // div (Buttons Control-Group)
        }
Esempio n. 2
0
        private static void PageItem(NavHtmlTextWritter textWriter, MvcHtmlString linkBlock, string cssClass = "")
        {
            if (cssClass != string.Empty)
            {
                textWriter.AddAttribute(HtmlTextWriterAttribute.Class, cssClass);
            }

            textWriter.RenderBeginTag(HtmlTextWriterTag.Li);
            textWriter.Write(linkBlock);
            textWriter.RenderEndTag();
        }
Esempio n. 3
0
        public static MvcHtmlString PageLinks(
            this HtmlHelper html,
            object queryObject,
            Func <object, string> urlActionDelegate,
            int linksToShow = 0)
        {
            var pagingInfoViewModel = queryObject as IPagingParameters;
            var result = new StringBuilder();

            if (pagingInfoViewModel != null)
            {
                var currentPage = pagingInfoViewModel.PageNumber + 1;
                var totalPages  = pagingInfoViewModel.TotalPages;
                linksToShow = (linksToShow == 0) ? totalPages : linksToShow;

                if (pagingInfoViewModel.TotalPages <= 1)
                {
                    return(MvcHtmlString.Create(string.Empty));
                }


                var    stringWriter = new StringWriter(result);
                string linkBlock    = string.Empty;

                using (var textWriter = new NavHtmlTextWritter(stringWriter))
                {
                    {
                        textWriter.AddAttribute(HtmlTextWriterAttribute.Class, Configurations.WebConfigurations.PagingConfigurations.PaginationCssClass);
                        textWriter.RenderBeginTag(HtmlTextWriterTag.Ul);
                        {
                            if (currentPage > 1)
                            {
                                pagingInfoViewModel.PageNumber = 1;
                                PageItem(textWriter, BasePagingExtensions.CreatePageLink(urlActionDelegate, queryObject, Configurations.WebConfigurations.PagingConfigurations.FirstPageText));


                                pagingInfoViewModel.PageNumber = currentPage - 1;
                                PageItem(textWriter, BasePagingExtensions.CreatePageLink(urlActionDelegate, queryObject, Configurations.WebConfigurations.PagingConfigurations.PreviousPageText));
                            }

                            // create page links
                            int start = 1;
                            int end   = totalPages;
                            start = PagerPounds(linksToShow, totalPages, currentPage, start, ref end);

                            for (int i = start; i <= end; i++)
                            {
                                pagingInfoViewModel.PageNumber = i;
                                if (i == currentPage)
                                {
                                    PageItem(textWriter, BasePagingExtensions.CreatePageLink(urlActionDelegate, queryObject, i.ToString()), Configurations.WebConfigurations.PagingConfigurations.ActivePageClass);
                                }
                                else
                                {
                                    PageItem(textWriter, BasePagingExtensions.CreatePageLink(urlActionDelegate, queryObject, i.ToString()));
                                }
                            }


                            // create 'Next >>' link
                            if (currentPage < totalPages)
                            {
                                pagingInfoViewModel.PageNumber = currentPage + 1;
                                PageItem(textWriter, BasePagingExtensions.CreatePageLink(urlActionDelegate, queryObject, Configurations.WebConfigurations.PagingConfigurations.NextPageText));

                                pagingInfoViewModel.PageNumber = totalPages;
                                PageItem(textWriter, BasePagingExtensions.CreatePageLink(urlActionDelegate, queryObject, Configurations.WebConfigurations.PagingConfigurations.LastPageText));
                            }


                            textWriter.RenderEndTag();
                        }
                    }
                }
            }
            return(MvcHtmlString.Create(result.ToString()));
        }