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(); } }
private static IHtmlContent BooleanTemplateCheckbox(IHtmlHelper htmlHelper, bool value) { return htmlHelper.CheckBox( expression: null, isChecked: value, htmlAttributes: CreateHtmlAttributes(htmlHelper, "check-box")); }
public ComponentTagHelper(IHttpContextAccessor contextAccessor, IBricsContextAccessor bricsContext) { _contextAccessor = contextAccessor; _bricsContext = bricsContext; _urlHelper = contextAccessor.HttpContext.RequestServices.GetService<IUrlHelper>(); _htmlHelper = contextAccessor.HttpContext.RequestServices.GetService<IHtmlHelper>(); }
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")); }
private static string BooleanTemplateDropDownList(IHtmlHelper html, bool? value) { return html.DropDownList( string.Empty, DefaultDisplayTemplates.TriStateValues(value), CreateHtmlAttributes(html, "list-box tri-state")) .ToString(); }
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); }
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); }
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; }
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; }
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; }
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; }
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(); }
/// <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))); }
/// <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))); }
/// <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); }
public EditModel(IRestaurantData restaurantData, IHtmlHelper htmlHelper) { _restaurantData = restaurantData; _htmlHelper = htmlHelper; }
public EditModel(IRestaurantData data, IHtmlHelper htmlHelper) { restaurantData = data; HtmlHelper = htmlHelper; }
/// <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); }
/// <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); }
/// <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())); }
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); }
/// <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);
/// <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);
public EditModel(IRestaurantData restaurantData, IHtmlHelper htmlHelper) { this.restaurantData = restaurantData; this.htmlHelper = htmlHelper; }
/// <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); }
/// <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)); }
/// <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)); }
public static IHtmlContent DisplayProperty(IHtmlHelper helper, object record, PropertySchema property) { return((property.Property is INavigation) ? DisplayNavigationProperty(helper, record, property) : DisplayDataProperty(helper, record, property)); }
public static string IsCollapsed(this IHtmlHelper html, string value) { return(string.IsNullOrEmpty(value) ? "collapse" : string.Empty); }
public static string IsCollapsed(this IHtmlHelper html, bool value) { return(value ? string.Empty : "collapse"); }
/// <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()); }
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); }
/// <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)); }
public static IHtmlContent TimeInputTemplate(IHtmlHelper htmlHelper) { ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:HH:mm:ss.fff}"); return GenerateTextBox(htmlHelper, inputType: "time"); }
/// <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); }
public static IHtmlContent FileInputTemplate(IHtmlHelper htmlHelper) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return GenerateTextBox(htmlHelper, inputType: "file"); }
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); } }
///<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())); }
/// <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); }
public static IHtmlContent DateTimeLocalInputTemplate(IHtmlHelper htmlHelper) { ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:yyyy-MM-ddTHH:mm:ss.fff}"); return GenerateTextBox(htmlHelper, inputType: "datetime-local"); }
///<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))); }
public static IHtmlContent DateInputTemplate(IHtmlHelper htmlHelper) { ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:yyyy-MM-dd}"); return GenerateTextBox(htmlHelper, inputType: "date"); }
///<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")); }
public static IHtmlContent NumberInputTemplate(IHtmlHelper htmlHelper) { return GenerateTextBox(htmlHelper, inputType: "number"); }
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)); }
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); }
public static async Task <IHtmlContent> DesignWidget(this IHtmlHelper html, DesignWidgetViewModel viewModel) { return(await html.PartialAsync("DesignWidget", viewModel)); }
private static IHtmlContent GenerateTextBox(IHtmlHelper htmlHelper, string inputType = null) { return GenerateTextBox(htmlHelper, inputType, htmlHelper.ViewData.TemplateInfo.FormattedModelValue); }
public static async Task <IHtmlContent> WidgetError(this IHtmlHelper html) { return(await html.PartialAsync("Widget.Error")); }
private static IHtmlContent GenerateTextBox(IHtmlHelper htmlHelper, object value, object htmlAttributes) { return htmlHelper.TextBox( current: null, value: value, format: null, htmlAttributes: htmlAttributes); }
public static async Task Pagin(this IHtmlHelper html, Pagin pagin) { await html.RenderPartialAsync("Partial_RegularPagination", pagin); }
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; } }
/// <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); }