IHtmlContent AddTemplate()
        {
            var table = this._htmlHelper.When(this._bindEvent)
                        .PreventDefault().StopPropagation()
                        .Ajax(this._ajaxGetAction)
                        .OnBegin(dsl =>
            {
                this._onBegin?.Invoke(dsl);
            })
                        .OnSuccess(dsl =>
            {
                dsl.Self().Insert.WithTemplateByUrl(GridTemplate.BuildTemplateUrl(_templateId)).Html();

                var noRecordContent = this._noRecordsSelector ?? GridOptions.Default.NoRecordsSelector ?? "<caption>No records to display.<caption>";
                dsl.Self().JQuery.Dom.Use(noRecordContent).Html().If(() => Selector.Result.IsEmpty());
                this._onSuccess?.Invoke(dsl);
            })
                        .OnError(dsl => dsl.Self().JQuery.Dom.Use("Error ajax get").Html())
                        .AsHtmlAttributes(new { id = this._contentTable, @class = "table " + (string.IsNullOrWhiteSpace(this._gridClass) ? GridOptions.Default.GetStyling() : this._gridClass) })
                        .ToTag(HtmlTag.Table);

            var divContent = new TagBuilder("div");

            divContent.AddCssClass("content-table");
            if (this._isScrolling)
            {
                divContent.MergeAttribute("style", "height: {0}px; overflow: auto;".F(this._contentTableHeight));
            }
            divContent.InnerHtml.AppendHtml(table);

            return(divContent);
            //return new MvcHtmlString("{0}{1}".F(divContent, CreateTemplate()));
        }
        IHtmlContent AddPageableTemplate()
        {
            var tableWithPageable = this._htmlHelper.When(this._bindEvent | JqueryBind.IncChangeUrl)
                                    .StopPropagation().PreventDefault()
                                    .Ajax(this._ajaxGetAction)
                                    .OnBegin(dsl =>
            {
                if (this._onBegin != null)
                {
                    this._onBegin(dsl);
                }
            })
                                    .OnSuccess(dsl =>
            {
                dsl.Self().JQuery.Dom.Use(Selector.Result.For <PagingResult <T> >(result => result.Items)).WithTemplateByUrl(GridTemplate.BuildTemplateUrl(_templateId)).Html();

                var insertDsl = dsl.WithId(_pagingContainer).JQuery.Dom.Use(Selector.Result.For <PagingResult <T> >(result => result.Paging));
                if (string.IsNullOrWhiteSpace(_customPagingTemplateView))
                {
                    insertDsl.WithTemplateByUrl(
                        GridTemplate.BuildTemplateUrl(_pagingTemplateId)).Html();
                }
                else
                {
                    insertDsl.WithTemplateByView(_customPagingTemplateView).Html();
                }

                var noRecordContent = this._noRecordsSelector ?? GridOptions.Default.NoRecordsSelector ?? "<caption>No records to display.<caption>";
                dsl.Self().JQuery.Dom.Use(noRecordContent).Html().If(() => Selector.Result.For <PagingResult <T> >(r => r.Items).IsEmpty());

                if (_showItemsCount)
                {
                    dsl.WithId(_pagingContainer).JQuery.Dom.Use(Selector.Result.For <PagingResult <T> >(result => result.PagingRange)).Append();
                }

                if (this._onSuccess != null)
                {
                    this._onSuccess(dsl);
                }
            })
                                    .OnError(dsl => dsl.Self().JQuery.Dom.Use("Error ajax get").Html())
                                    .AsHtmlAttributes(new { id = this._contentTable, @class = "table " + (string.IsNullOrWhiteSpace(this._gridClass) ? GridOptions.Default.GetStyling() : this._gridClass) })
                                    .ToTag(HtmlTag.Table);

            var divContent = new TagBuilder("div");

            divContent.AddCssClass("content-table");
            divContent.InnerHtml.AppendHtml(tableWithPageable);

            var divPagingContainer = new TagBuilder("div");

            divPagingContainer.GenerateId(_pagingContainer, "-");
            divPagingContainer.AddCssClass("pagination");

            var selectPageSizes = this._htmlHelper.DropDownList("PageSize", new SelectList(_pageSizesArray ?? new int[] { 5, 10, 50, 100 }), null,
                                                                _htmlHelper.When(JqueryBind.Change)
                                                                .OnSuccess(dsl =>
            {
                dsl.Self().Store.Hash.Insert();
                dsl.Self().Store.Hash.Manipulate(manipulateDsl => manipulateDsl.Set("Page", 1));
            })
                                                                .AsHtmlAttributes(new { style = "width: 50px;", id = _pageSizesSelect }));
            TagBuilder tb = new TagBuilder("div");

            tb.InnerHtml.AppendHtml(divContent);
            tb.InnerHtml.AppendHtml(divPagingContainer);
            if (_showPageSizes)
            {
                tb.InnerHtml.AppendHtml(selectPageSizes);
            }
            return(tb);
            //return new MvcHtmlString("{0}{1}{2}{3}".F(divContent,
            //                                          CreateTemplate(),
            //                                          divPagingContainer.ToString(),
            //                                          _showPageSizes ? selectPageSizes.ToString() : ""));
        }