예제 #1
0
        private static string buildActionLink(IHtmlHelper helper,
                                      string linkText,
                                      int pageParam)
        {
            if (helper.ViewContext.HttpContext.Request.QueryString.HasValue)
            {
                var queryString = QueryHelpers.ParseQuery(helper.ViewContext.HttpContext.Request.QueryString.Value);
                string[] sort, categoryId;
                queryString.TryGetValue("SortExpression", out sort);
                queryString.TryGetValue("CategoryId", out categoryId);

                return helper.ActionLink(linkText,
                               helper.ViewContext.RouteData.Values["action"].ToString(),
                               new
                               {
                                   SortExpression = sort,
                                   CategoryId = categoryId,
                                   Page = pageParam
                               }).ToString();
            }
            else
            {
                return helper.ActionLink(linkText,
                               helper.ViewContext.RouteData.Values["action"].ToString(),
                               new
                               {
                                   Page = pageParam
                               }).ToString();
            }
        }
예제 #2
0
 private static IHtmlContent BooleanTemplateCheckbox(IHtmlHelper htmlHelper, bool value)
 {
     return htmlHelper.CheckBox(
         expression: null,
         isChecked: value,
         htmlAttributes: CreateHtmlAttributes(htmlHelper, "check-box"));
 }
예제 #3
0
 public ComponentTagHelper(IHttpContextAccessor contextAccessor, IBricsContextAccessor bricsContext)
 {
     _contextAccessor = contextAccessor;
     _bricsContext = bricsContext;
     _urlHelper = contextAccessor.HttpContext.RequestServices.GetService<IUrlHelper>();
     _htmlHelper = contextAccessor.HttpContext.RequestServices.GetService<IHtmlHelper>();
 }
예제 #4
0
 private static IHtmlContent BooleanTemplateDropDownList(IHtmlHelper htmlHelper, bool? value)
 {
     return htmlHelper.DropDownList(
         expression: null,
         selectList: DefaultDisplayTemplates.TriStateValues(value),
         optionLabel: null,
         htmlAttributes: CreateHtmlAttributes(htmlHelper, "list-box tri-state"));
 }
예제 #5
0
 private static string BooleanTemplateDropDownList(IHtmlHelper html, bool? value)
 {
     return html.DropDownList(
         string.Empty,
         DefaultDisplayTemplates.TriStateValues(value),
         CreateHtmlAttributes(html, "list-box tri-state"))
             .ToString();
 }
예제 #6
0
        public void AddBackofficeBottom(string urlstring, IUrlHelper url, IHtmlHelper html)
        {
            const string prefix = @"~/Areas/Backoffice/Scripts/framework/";
            urlstring = urlstring.TrimStart('/');

            var path = string.Format("{0}{1}", url.Content(prefix), (urlstring.EndsWith(".js") ? urlstring : urlstring + ".js"));
            html.Statics().FooterScripts.Add(path);
        }
예제 #7
0
        public HtmlGridTests()
        {
            html = Substitute.For<IHtmlHelper>();
            html.ViewContext.Returns(new ViewContext());
            html.ViewContext.HttpContext = new DefaultHttpContext();
            grid = new Grid<GridModel>(new GridModel[8]);

            htmlGrid = new HtmlGrid<GridModel>(html, grid);
            grid.Columns.Add(model => model.Name);
            grid.Columns.Add(model => model.Sum);
        }
예제 #8
0
        public static IHtmlContent BooleanTemplate(IHtmlHelper htmlHelper)
        {
            bool? value = null;
            if (htmlHelper.ViewData.Model != null)
            {
                value = Convert.ToBoolean(htmlHelper.ViewData.Model, CultureInfo.InvariantCulture);
            }

            return htmlHelper.ViewData.ModelMetadata.IsNullableValueType ?
                BooleanTemplateDropDownList(htmlHelper, value) :
                BooleanTemplateCheckbox(htmlHelper, value ?? false);
        }
 private static string SectionContent(IHtmlHelper html, ISitePage sitepage, IPageSection model)
 {
     using (StringWriter result = new StringWriter())
     {
         foreach (var item in model.Items)
         {
             item.Page = sitepage;
             html.Partial(item.Template, item).WriteTo(result, HtmlEncoder.Default);
         }
         return result.ToString();
     }
 }
        private static string BooleanTemplateCheckbox(bool value, IHtmlHelper htmlHelper)
        {
            var inputTag = new TagBuilder("input", htmlHelper.HtmlEncoder);
            inputTag.AddCssClass("check-box");
            inputTag.Attributes["disabled"] = "disabled";
            inputTag.Attributes["type"] = "checkbox";
            if (value)
            {
                inputTag.Attributes["checked"] = "checked";
            }

            return inputTag.ToString(TagRenderMode.SelfClosing);
        }
 //workaround forr issue https://github.com/aspnet/Mvc/issues/2430
 private static string getEnumDisplayName(Type type, string o, IHtmlHelper h)
 {
     string displayName = null;
     
     foreach (SelectListItem item in h.GetEnumSelectList(type))
     {
         if (o == item.Value)
         {
             displayName = item.Text ?? item.Value;
         }
     }
     return displayName;
 }
 public GridTagHelper(IOptions<MvcViewOptions> optionsAccessor,
     IHtmlHelper html, 
     IHttpContextAccessor httpAccessor, IViewComponentHelper component, 
     IUrlHelperFactory urlHelperFactory,
     IStringLocalizerFactory factory)
 {
     IdAttributeDotReplacement = optionsAccessor.Value.HtmlHelperOptions.IdAttributeDotReplacement;
     this.html = html;
     this.httpAccessor = httpAccessor;
     this.component = component;
     this.urlHelperFactory = urlHelperFactory;
     this.factory = factory;
 }
예제 #13
0
        public static StaticsHelper GetInstance(IHtmlHelper htmlHelper)
        {
            const string instanceKey = "8F3AC534-E5B1-4C51-B5A9-ED0EAC731633";

            var context = htmlHelper.ViewContext.HttpContext;
            if (context == null) return null;

            var assetsHelper = (StaticsHelper)context.Items[instanceKey];

            if (assetsHelper == null)
                context.Items.Add(instanceKey, assetsHelper = new StaticsHelper());

            return assetsHelper;
        }
예제 #14
0
        private static IHtmlContent BooleanTemplateDropDownList(IHtmlHelper htmlHelper, bool? value)
        {
            var selectTag = new TagBuilder("select");
            selectTag.AddCssClass("list-box");
            selectTag.AddCssClass("tri-state");
            selectTag.Attributes["disabled"] = "disabled";

            foreach (var item in TriStateValues(value))
            {
                selectTag.InnerHtml.Append(DefaultHtmlGenerator.GenerateOption(item, item.Text));
            }
            
            return selectTag;
        }
예제 #15
0
        private static IHtmlContent BooleanTemplateCheckbox(bool value, IHtmlHelper htmlHelper)
        {
            var inputTag = new TagBuilder("input");
            inputTag.AddCssClass("check-box");
            inputTag.Attributes["disabled"] = "disabled";
            inputTag.Attributes["type"] = "checkbox";
            if (value)
            {
                inputTag.Attributes["checked"] = "checked";
            }

            inputTag.TagRenderMode = TagRenderMode.SelfClosing;
            return inputTag;
        }
        public LookupExtensionsTests()
        {
            html = MockHtmlHelper();
            lookup = new TestLookup<TestModel>();

            lookup.Filter.Page = 2;
            lookup.Filter.Rows = 11;
            lookup.Filter.Search = "Test";
            lookup.AdditionalFilters.Clear();
            lookup.Filter.SortColumn = "First";
            lookup.Title = "Dialog lookup title";
            lookup.AdditionalFilters.Add("Add1");
            lookup.AdditionalFilters.Add("Add2");
            lookup.Url = "http://localhost/Lookup";
            lookup.Filter.SortOrder = LookupSortOrder.Desc;
        }
예제 #17
0
        private static HtmlString createPostBackLink(IHtmlHelper helper,
                                              string text,
                                              string actionName,
                                              string controller)
        {
            var vpc = new VirtualPathContext(
                helper.ViewContext.HttpContext,
                null,
                (new RouteValueDictionary {
                      { "controller", controller },
                      { "action", actionName } })

                      );
            var actionUrl = helper.ViewContext.RouteData.Routers[0].GetVirtualPath(vpc);

            return new HtmlString(String.Format(@"<a href=""#"" class=""btn btn-default"" onclick=""wizard.WizardSubmit('{0}')"">{1}</a>",
                  actionUrl, text));
        }
        private static string BooleanTemplateDropDownList(IHtmlHelper htmlHelper, bool? value)
        {
            var selectTag = new TagBuilder("select", htmlHelper.HtmlEncoder);
            selectTag.AddCssClass("list-box");
            selectTag.AddCssClass("tri-state");
            selectTag.Attributes["disabled"] = "disabled";

            var builder = new StringBuilder();
            builder.Append(selectTag.ToString(TagRenderMode.StartTag));

            foreach (var item in TriStateValues(value))
            {
                var encodedText = htmlHelper.Encode(item.Text);
                var option = DefaultHtmlGenerator.GenerateOption(item, encodedText, htmlHelper.HtmlEncoder);
                builder.Append(option);
            }

            builder.Append(selectTag.ToString(TagRenderMode.EndTag));
            return builder.ToString();
        }
예제 #19
0
        /// <summary>
        /// Generate all CSS parts
        /// </summary>
        /// <param name="html">HTML helper</param>
        /// <param name="urlHelper">URL Helper</param>
        /// <param name="location">A location of the script element</param>
        /// <param name="bundleFiles">A value indicating whether to bundle script elements</param>
        /// <returns>Generated string</returns>
        public static IHtmlContent GrandCssFiles(this IHtmlHelper html, IUrlHelper urlHelper, ResourceLocation location, bool?bundleFiles = null)
        {
            var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>();

            return(new HtmlString(pageHeadBuilder.GenerateCssFiles(urlHelper, location, bundleFiles)));
        }
예제 #20
0
        /// <summary>
        /// Generate all inline script parts
        /// </summary>
        /// <param name="html">HTML helper</param>
        /// <param name="urlHelper">URL Helper</param>
        /// <param name="location">A location of the script element</param>
        /// <returns>Generated string</returns>
        public static IHtmlContent NopInlineScripts(this IHtmlHelper html, IUrlHelper urlHelper, ResourceLocation location)
        {
            var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>();

            return(new HtmlString(pageHeadBuilder.GenerateInlineScripts(urlHelper, location)));
        }
예제 #21
0
        /// <summary>
        /// Append canonical URL element to the <![CDATA[<head>]]>
        /// </summary>
        /// <param name="html">HTML helper</param>
        /// <param name="part">Canonical URL part</param>
        public static void AppendCanonicalUrlParts(this IHtmlHelper html, string part)
        {
            var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>();

            pageHeadBuilder.AppendCanonicalUrlParts(part);
        }
예제 #22
0
 public EditModel(IRestaurantData restaurantData,
                  IHtmlHelper htmlHelper)
 {
     _restaurantData = restaurantData;
     _htmlHelper     = htmlHelper;
 }
예제 #23
0
 public EditModel(IRestaurantData data, IHtmlHelper htmlHelper)
 {
     restaurantData = data;
     HtmlHelper     = htmlHelper;
 }
예제 #24
0
 /// <summary>
 /// Append script element
 /// </summary>
 /// <param name="html">HTML helper</param>
 /// <param name="src">Script path (minified version)</param>
 /// <param name="debugSrc">Script path (full debug version). If empty, then minified version will be used</param>
 /// <param name="excludeFromBundle">A value indicating whether to exclude this script from bundling</param>
 /// <param name="isAsync">A value indicating whether to add an attribute "async" or not for js files</param>
 public static void AppendScriptParts(this IHtmlHelper html, string src, string debugSrc = "",
                                      bool excludeFromBundle = false, bool isAsync = false)
 {
     AppendScriptParts(html, ResourceLocation.Head, src, debugSrc, excludeFromBundle, isAsync);
 }
예제 #25
0
 /// <summary>
 /// Append CSS element
 /// </summary>
 /// <param name="html">HTML helper</param>
 /// <param name="src">Script path (minified version)</param>
 /// <param name="debugSrc">Script path (full debug version). If empty, then minified version will be used</param>
 /// <param name="excludeFromBundle">A value indicating whether to exclude this script from bundling</param>
 public static void AppendCssFileParts(this IHtmlHelper html, string src, string debugSrc = "", bool excludeFromBundle = false)
 {
     AppendCssFileParts(html, ResourceLocation.Head, src, debugSrc, excludeFromBundle);
 }
예제 #26
0
        /// <summary>
        /// Generate all custom elements
        /// </summary>
        /// <param name="html">HTML helper</param>
        /// <returns>Generated string</returns>
        public static IHtmlContent GrandHeadCustom(this IHtmlHelper html)
        {
            var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>();

            return(new HtmlString(pageHeadBuilder.GenerateHeadCustom()));
        }
예제 #27
0
 public static IHtmlContent EmailAddressInputTemplate(IHtmlHelper htmlHelper)
 {
     return GenerateTextBox(htmlHelper, inputType: "email");
 }
        public static string PageClass(this IHtmlHelper htmlHelper)
        {
            string currentAction = (string)htmlHelper.ViewContext.RouteData.Values["action"];

            return(currentAction);
        }
예제 #29
0
 /// <summary>
 /// Renders the <typeparamref name="TComponent"/>.
 /// </summary>
 /// <param name="htmlHelper">The <see cref="IHtmlHelper"/>.</param>
 /// <param name="parameters">An <see cref="object"/> containing the parameters to pass
 /// to the component.</param>
 /// <param name="renderMode">The <see cref="RenderMode"/> for the component.</param>
 /// <returns>The HTML produced by the rendered <typeparamref name="TComponent"/>.</returns>
 public static Task <IHtmlContent> RenderComponentAsync <TComponent>(
     this IHtmlHelper htmlHelper,
     RenderMode renderMode,
     object parameters) where TComponent : IComponent
 => RenderComponentAsync(htmlHelper, typeof(TComponent), renderMode, parameters);
예제 #30
0
 /// <summary>
 /// Renders the <typeparamref name="TComponent"/>.
 /// </summary>
 /// <param name="htmlHelper">The <see cref="IHtmlHelper"/>.</param>
 /// <param name="renderMode">The <see cref="RenderMode"/> for the component.</param>
 /// <returns>The HTML produced by the rendered <typeparamref name="TComponent"/>.</returns>
 public static Task <IHtmlContent> RenderComponentAsync <TComponent>(this IHtmlHelper htmlHelper, RenderMode renderMode) where TComponent : IComponent
 => RenderComponentAsync <TComponent>(htmlHelper, renderMode, parameters : null);
예제 #31
0
 public EditModel(IRestaurantData restaurantData,
                  IHtmlHelper htmlHelper)
 {
     this.restaurantData = restaurantData;
     this.htmlHelper     = htmlHelper;
 }
예제 #32
0
        /// <summary>
        /// Append meta description element to the <![CDATA[<head>]]>
        /// </summary>
        /// <param name="html">HTML helper</param>
        /// <param name="part">Meta description part</param>
        public static void AppendMetaDescriptionParts(this IHtmlHelper html, string part)
        {
            var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>();

            pageHeadBuilder.AppendMetaDescriptionParts(part);
        }
예제 #33
0
 /// <summary>
 /// Returns the formatted value for the specified <paramref name="expression"/>.
 /// </summary>
 /// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
 /// <param name="expression">Expression name, relative to the current model.</param>
 /// <returns>A <see cref="string"/> containing the formatted value.</returns>
 /// <remarks>
 /// Converts the expression result to a <see cref="string"/> directly.
 /// </remarks>
 public static string Value([NotNull] this IHtmlHelper htmlHelper, string expression)
 {
     return(htmlHelper.Value(expression, format: null));
 }
예제 #34
0
 /// <summary>
 /// Returns the formatted value for the specified <paramref name="expression"/>.
 /// </summary>
 /// <param name="htmlHelper">The <see cref="IHtmlHelper{TModel}"/> instance this method extends.</param>
 /// <param name="expression">An expression to be evaluated against the current model.</param>
 /// <typeparam name="TModel">The type of the model.</typeparam>
 /// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
 /// <returns>A <see cref="string"/> containing the formatted value.</returns>
 /// <remarks>
 /// Converts the <paramref name="expression"/> result to a <see cref="string"/> directly.
 /// </remarks>
 public static string ValueFor <TModel, TResult>(
     [NotNull] this IHtmlHelper <TModel> htmlHelper,
     [NotNull] Expression <Func <TModel, TResult> > expression)
 {
     return(htmlHelper.ValueFor(expression, format: null));
 }
예제 #35
0
 public static IHtmlContent DisplayProperty(IHtmlHelper helper, object record, PropertySchema property)
 {
     return((property.Property is INavigation) ?
            DisplayNavigationProperty(helper, record, property) :
            DisplayDataProperty(helper, record, property));
 }
예제 #36
0
 public static string IsCollapsed(this IHtmlHelper html, string value)
 {
     return(string.IsNullOrEmpty(value) ? "collapse" : string.Empty);
 }
예제 #37
0
 public static string IsCollapsed(this IHtmlHelper html, bool value)
 {
     return(value ? string.Empty : "collapse");
 }
예제 #38
0
        /// <summary>
        /// Get system name of admin menu item that should be selected (expanded)
        /// </summary>
        /// <param name="html">HTML helper</param>
        /// <returns>System name</returns>
        public static string GetActiveMenuItemSystemName(this IHtmlHelper html)
        {
            var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>();

            return(pageHeadBuilder.GetActiveMenuItemSystemName());
        }
예제 #39
0
        private static IHtmlContent GenerateTextBox(IHtmlHelper htmlHelper, string inputType, object value)
        {
            var htmlAttributes =
                CreateHtmlAttributes(htmlHelper, className: "text-box single-line", inputType: inputType);

            return GenerateTextBox(htmlHelper, value, htmlAttributes);
        }
예제 #40
0
 /// <summary>
 /// Returns the formatted value for the current model.
 /// </summary>
 /// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
 /// <param name="format">
 /// The composite format <see cref="string"/> (see http://msdn.microsoft.com/en-us/library/txafckwd.aspx).
 /// </param>
 /// <returns>A <see cref="string"/> containing the formatted value.</returns>
 /// <remarks>
 /// Converts the model value to a <see cref="string"/> directly if
 /// <paramref name="format"/> is <c>null</c> or empty.
 /// </remarks>
 public static string ValueForModel([NotNull] this IHtmlHelper htmlHelper, string format)
 {
     return(htmlHelper.Value(expression: null, format: format));
 }
예제 #41
0
 public static IHtmlContent TimeInputTemplate(IHtmlHelper htmlHelper)
 {
     ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:HH:mm:ss.fff}");
     return GenerateTextBox(htmlHelper, inputType: "time");
 }
예제 #42
0
        /// <summary>
        /// Add meta keyword element to the <![CDATA[<head>]]>
        /// </summary>
        /// <param name="html">HTML helper</param>
        /// <param name="part">Meta keyword part</param>
        public static void AddMetaKeywordParts(this IHtmlHelper html, string part)
        {
            var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>();

            pageHeadBuilder.AddMetaKeywordParts(part);
        }
예제 #43
0
        public static IHtmlContent FileInputTemplate(IHtmlHelper htmlHelper)
        {
            if (htmlHelper == null)
            {
                throw new ArgumentNullException(nameof(htmlHelper));
            }

            return GenerateTextBox(htmlHelper, inputType: "file");
        }
예제 #44
0
        private static void ApplyRfc3339DateFormattingIfNeeded(IHtmlHelper htmlHelper, string format)
        {
            if (htmlHelper.Html5DateRenderingMode != Html5DateRenderingMode.Rfc3339)
            {
                return;
            }

            var metadata = htmlHelper.ViewData.ModelMetadata;
            var value = htmlHelper.ViewData.Model;
            if (htmlHelper.ViewData.TemplateInfo.FormattedModelValue != value && metadata.HasNonDefaultEditFormat)
            {
                return;
            }

            if (value is DateTime || value is DateTimeOffset)
            {
                htmlHelper.ViewData.TemplateInfo.FormattedModelValue =
                    string.Format(CultureInfo.InvariantCulture, format, value);
            }
        }
예제 #45
0
 ///<summary>
 ///	Displays a configurable paging control for instances of PagedList.
 ///</summary>
 ///<param name = "html">This method is meant to hook off HtmlHelper as an extension method.</param>
 ///<param name = "list">The PagedList to use as the data source.</param>
 ///<param name = "generatePageUrl">A function that takes the page number of the desired page and returns a URL-string that will load that page.</param>
 ///<returns>Outputs the paging control HTML.</returns>
 public static HtmlString PagedListPager(this IHtmlHelper html,
                                         IPagedList list,
                                         Func <int, string> generatePageUrl)
 {
     return(PagedListPager(html, list, generatePageUrl, new PagedListRenderOptions()));
 }
예제 #46
0
        /// <summary>
        /// Specify system name of admin menu item that should be selected (expanded)
        /// </summary>
        /// <param name="html">HTML helper</param>
        /// <param name="systemName">System name</param>
        public static void SetActiveMenuItemSystemName(this IHtmlHelper html, string systemName)
        {
            var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>();

            pageHeadBuilder.SetActiveMenuItemSystemName(systemName);
        }
예제 #47
0
 public static IHtmlContent DateTimeLocalInputTemplate(IHtmlHelper htmlHelper)
 {
     ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:yyyy-MM-ddTHH:mm:ss.fff}");
     return GenerateTextBox(htmlHelper, inputType: "datetime-local");
 }
예제 #48
0
        ///<summary>
        ///	Displays a configurable paging control for instances of PagedList.
        ///</summary>
        ///<param name = "html">This method is meant to hook off HtmlHelper as an extension method.</param>
        ///<param name = "list">The PagedList to use as the data source.</param>
        ///<param name = "generatePageUrl">A function that takes the page number  of the desired page and returns a URL-string that will load that page.</param>
        ///<param name = "options">Formatting options.</param>
        ///<returns>Outputs the paging control HTML.</returns>
        public static HtmlString PagedListPager(this IHtmlHelper html,
                                                IPagedList list,
                                                Func <int, string> generatePageUrl,
                                                PagedListRenderOptionsBase options)
        {
            if (options.Display == PagedListDisplayMode.Never || (options.Display == PagedListDisplayMode.IfNeeded && list.PageCount <= 1))
            {
                return(null);
            }

            var listItemLinks = new List <TagBuilder>();

            //calculate start and end of range of page numbers
            var firstPageToDisplay   = 1;
            var lastPageToDisplay    = list.PageCount;
            var pageNumbersToDisplay = lastPageToDisplay;

            if (options.MaximumPageNumbersToDisplay.HasValue && list.PageCount > options.MaximumPageNumbersToDisplay)
            {
                // cannot fit all pages into pager
                var maxPageNumbersToDisplay = options.MaximumPageNumbersToDisplay.Value;
                firstPageToDisplay = list.PageNumber - maxPageNumbersToDisplay / 2;
                if (firstPageToDisplay < 1)
                {
                    firstPageToDisplay = 1;
                }
                pageNumbersToDisplay = maxPageNumbersToDisplay;
                lastPageToDisplay    = firstPageToDisplay + pageNumbersToDisplay - 1;
                if (lastPageToDisplay > list.PageCount)
                {
                    firstPageToDisplay = list.PageCount - maxPageNumbersToDisplay + 1;
                }
            }

            //first
            if (options.DisplayLinkToFirstPage == PagedListDisplayMode.Always || (options.DisplayLinkToFirstPage == PagedListDisplayMode.IfNeeded && firstPageToDisplay > 1))
            {
                listItemLinks.Add(First(list, generatePageUrl, options));
            }

            //previous
            if (options.DisplayLinkToPreviousPage == PagedListDisplayMode.Always || (options.DisplayLinkToPreviousPage == PagedListDisplayMode.IfNeeded && !list.IsFirstPage))
            {
                listItemLinks.Add(Previous(list, generatePageUrl, options));
            }

            //text
            if (options.DisplayPageCountAndCurrentLocation)
            {
                listItemLinks.Add(PageCountAndLocationText(list, options));
            }

            //text
            if (options.DisplayItemSliceAndTotal)
            {
                listItemLinks.Add(ItemSliceAndTotalText(list, options));
            }

            //page
            if (options.DisplayLinkToIndividualPages)
            {
                //if there are previous page numbers not displayed, show an ellipsis
                if (options.DisplayEllipsesWhenNotShowingAllPageNumbers && firstPageToDisplay > 1)
                {
                    listItemLinks.Add(Ellipses(options));
                }

                foreach (var i in Enumerable.Range(firstPageToDisplay, pageNumbersToDisplay))
                {
                    //show delimiter between page numbers
                    if (i > firstPageToDisplay && !string.IsNullOrWhiteSpace(options.DelimiterBetweenPageNumbers))
                    {
                        listItemLinks.Add(WrapInListItem(options.DelimiterBetweenPageNumbers));
                    }

                    //show page number link
                    listItemLinks.Add(Page(i, list, generatePageUrl, options));
                }

                //if there are subsequent page numbers not displayed, show an ellipsis
                if (options.DisplayEllipsesWhenNotShowingAllPageNumbers && (firstPageToDisplay + pageNumbersToDisplay - 1) < list.PageCount)
                {
                    listItemLinks.Add(Ellipses(options));
                }
            }

            //next
            if (options.DisplayLinkToNextPage == PagedListDisplayMode.Always || (options.DisplayLinkToNextPage == PagedListDisplayMode.IfNeeded && !list.IsLastPage))
            {
                listItemLinks.Add(Next(list, generatePageUrl, options));
            }

            //last
            if (options.DisplayLinkToLastPage == PagedListDisplayMode.Always || (options.DisplayLinkToLastPage == PagedListDisplayMode.IfNeeded && lastPageToDisplay < list.PageCount))
            {
                listItemLinks.Add(Last(list, generatePageUrl, options));
            }

            if (listItemLinks.Any())
            {
                //append class to first item in list?
                if (!string.IsNullOrWhiteSpace(options.ClassToApplyToFirstListItemInPager))
                {
                    listItemLinks.First().AddCssClass(options.ClassToApplyToFirstListItemInPager);
                }

                //append class to last item in list?
                if (!string.IsNullOrWhiteSpace(options.ClassToApplyToLastListItemInPager))
                {
                    listItemLinks.Last().AddCssClass(options.ClassToApplyToLastListItemInPager);
                }

                //append classes to all list item links
                foreach (var li in listItemLinks)
                {
                    foreach (var c in options.LiElementClasses ?? Enumerable.Empty <string>())
                    {
                        li.AddCssClass(c);
                    }
                }
            }

            //collapse all of the list items into one big string
            var listItemLinksString = listItemLinks.Aggregate(
                new StringBuilder(),
                (sb, listItem) => sb.Append(TagBuilderToString(listItem, options.HtmlEncoder)),
                sb => sb.ToString()
                );

            var ul = new TagBuilder("ul");

            AppendHtml(ul, listItemLinksString);
            foreach (var c in options.UlElementClasses ?? Enumerable.Empty <string>())
            {
                ul.AddCssClass(c);
            }

            if (options.UlElementattributes != null)
            {
                foreach (var c in options.UlElementattributes)
                {
                    ul.MergeAttribute(c.Key, c.Value);
                }
            }

            var outerDiv = new TagBuilder("div");

            foreach (var c in options.ContainerDivClasses ?? Enumerable.Empty <string>())
            {
                outerDiv.AddCssClass(c);
            }
            AppendHtml(outerDiv, TagBuilderToString(ul, options.HtmlEncoder));

            return(new HtmlString(TagBuilderToString(outerDiv, options.HtmlEncoder)));
        }
예제 #49
0
 public static IHtmlContent DateInputTemplate(IHtmlHelper htmlHelper)
 {
     ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:yyyy-MM-dd}");
     return GenerateTextBox(htmlHelper, inputType: "date");
 }
예제 #50
0
 ///<summary>
 /// Displays a configurable "Go To Page:" form for instances of PagedList.
 ///</summary>
 ///<param name="html">This method is meant to hook off HtmlHelper as an extension method.</param>
 ///<param name="list">The PagedList to use as the data source.</param>
 ///<param name="formAction">The URL this form should submit the GET request to.</param>
 ///<returns>Outputs the "Go To Page:" form HTML.</returns>
 public static HtmlString PagedListGoToPageForm(this IHtmlHelper html, IPagedList list, string formAction)
 {
     return(PagedListGoToPageForm(html, list, formAction, "page"));
 }
예제 #51
0
 public static IHtmlContent NumberInputTemplate(IHtmlHelper htmlHelper)
 {
     return GenerateTextBox(htmlHelper, inputType: "number");
 }
예제 #52
0
        public static IElementGenerator <T> GetGenerator <T>(IHtmlHelper <T> helper) where T : class
        {
            var library = helper.ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();

            return(ElementGenerator <T> .For(library, t => helper.ViewContext.HttpContext.RequestServices.GetService(t), helper.ViewData.Model));
        }
예제 #53
0
        public static IHtmlContent FileCollectionInputTemplate(IHtmlHelper htmlHelper)
        {
            if (htmlHelper == null)
            {
                throw new ArgumentNullException(nameof(htmlHelper));
            }

            var htmlAttributes =
                CreateHtmlAttributes(htmlHelper, className: "text-box single-line", inputType: "file");
            htmlAttributes["multiple"] = "multiple";

            return GenerateTextBox(htmlHelper, htmlHelper.ViewData.TemplateInfo.FormattedModelValue, htmlAttributes);
        }
예제 #54
0
 public static async Task <IHtmlContent> DesignWidget(this IHtmlHelper html, DesignWidgetViewModel viewModel)
 {
     return(await html.PartialAsync("DesignWidget", viewModel));
 }
예제 #55
0
 private static IHtmlContent GenerateTextBox(IHtmlHelper htmlHelper, string inputType = null)
 {
     return GenerateTextBox(htmlHelper, inputType, htmlHelper.ViewData.TemplateInfo.FormattedModelValue);
 }
예제 #56
0
 public static async Task <IHtmlContent> WidgetError(this IHtmlHelper html)
 {
     return(await html.PartialAsync("Widget.Error"));
 }
예제 #57
0
 private static IHtmlContent GenerateTextBox(IHtmlHelper htmlHelper, object value, object htmlAttributes)
 {
     return htmlHelper.TextBox(
         current: null,
         value: value,
         format: null,
         htmlAttributes: htmlAttributes);
 }
예제 #58
0
 public static async Task Pagin(this IHtmlHelper html, Pagin pagin)
 {
     await html.RenderPartialAsync("Partial_RegularPagination", pagin);
 }
예제 #59
0
        public static IHtmlContent CollectionTemplate(IHtmlHelper htmlHelper)
        {
            var viewData = htmlHelper.ViewData;
            var model = viewData.Model;
            if (model == null)
            {
                return HtmlString.Empty;
            }

            var collection = model as IEnumerable;
            if (collection == null)
            {
                // Only way we could reach here is if user passed templateName: "Collection" to an Editor() overload.
                throw new InvalidOperationException(Resources.FormatTemplates_TypeMustImplementIEnumerable(
                    "Collection", model.GetType().FullName, typeof(IEnumerable).FullName));
            }

            var elementMetadata = htmlHelper.ViewData.ModelMetadata.ElementMetadata;
            Debug.Assert(elementMetadata != null);
            var typeInCollectionIsNullableValueType = elementMetadata.IsNullableValueType;

            var serviceProvider = htmlHelper.ViewContext.HttpContext.RequestServices;
            var metadataProvider = serviceProvider.GetRequiredService<IModelMetadataProvider>();

            // Use typeof(string) instead of typeof(object) for IEnumerable collections. Neither type is Nullable<T>.
            if (elementMetadata.ModelType == typeof(object))
            {
                elementMetadata = metadataProvider.GetMetadataForType(typeof(string));
            }

            var oldPrefix = viewData.TemplateInfo.HtmlFieldPrefix;
            try
            {
                viewData.TemplateInfo.HtmlFieldPrefix = string.Empty;

                var fieldNameBase = oldPrefix;
                var result = new HtmlContentBuilder();
                var viewEngine = serviceProvider.GetRequiredService<ICompositeViewEngine>();
                var viewBufferScope = serviceProvider.GetRequiredService<IViewBufferScope>();

                var index = 0;
                foreach (var item in collection)
                {
                    var itemMetadata = elementMetadata;
                    if (item != null && !typeInCollectionIsNullableValueType)
                    {
                        itemMetadata = metadataProvider.GetMetadataForType(item.GetType());
                    }

                    var modelExplorer = new ModelExplorer(
                        metadataProvider,
                        container: htmlHelper.ViewData.ModelExplorer,
                        metadata: itemMetadata,
                        model: item);
                    var fieldName = string.Format(CultureInfo.InvariantCulture, "{0}[{1}]", fieldNameBase, index++);

                    var templateBuilder = new TemplateBuilder(
                        viewEngine,
                        viewBufferScope,
                        htmlHelper.ViewContext,
                        htmlHelper.ViewData,
                        modelExplorer,
                        htmlFieldName: fieldName,
                        templateName: null,
                        readOnly: false,
                        additionalViewData: null);
                    result.AppendHtml(templateBuilder.Build());
                }

                return result;
            }
            finally
            {
                viewData.TemplateInfo.HtmlFieldPrefix = oldPrefix;
            }
        }
예제 #60
0
        /// <summary>
        /// Append inline script element
        /// </summary>
        /// <param name="html">HTML helper</param>
        /// <param name="location">A location of the script element</param>
        /// <param name="script">Script</param>
        public static void AppendInlineScriptParts(this IHtmlHelper html, ResourceLocation location, string script)
        {
            var pageHeadBuilder = EngineContext.Current.Resolve <IPageHeadBuilder>();

            pageHeadBuilder.AppendInlineScriptParts(location, script);
        }