protected override void ProcessCore(TagHelperContext context, TagHelperOutput output) { if (For != null) { TargetInputSelector = "#" + HtmlHelper.GenerateIdFromName(For.Name); } var options = new { entityType = EntityType, url = UrlHelper.Action("Picker", "Entity", new { area = string.Empty }), caption = (DialogTitle.NullEmpty() ?? Caption).HtmlEncode(), disableIf = DisableGroupedProducts ? "groupedproduct" : (DisableBundleProducts ? "notsimpleproduct" : null), disableIds = DisabledEntityIds == null ? null : string.Join(',', DisabledEntityIds), thumbZoomer = EnableThumbZoomer, highligtSearchTerm = HighlightSearchTerm, returnField = FieldName, delim = Delimiter, targetInput = TargetInputSelector, selected = Selected, appendMode = AppendMode, maxItems = MaxItems, onDialogLoading = OnDialogLoadingHandler, onDialogLoaded = OnDialogLoadedHandler, onSelectionCompleted = OnSelectionCompletedHandler }; var buttonId = "entpicker-toggle-" + CommonHelper.GenerateRandomInteger(); output.TagName = "button"; output.TagMode = TagMode.StartTagAndEndTag; output.MergeAttribute("id", buttonId); output.MergeAttribute("type", "button"); output.AppendCssClass("btn btn-secondary"); if (IconCssClass.HasValue()) { output.Content.AppendHtml($"<i class='{ IconCssClass }'></i>"); } if (Caption.HasValue()) { output.Content.AppendHtml($"<span>{ Caption }</span>"); } var json = JsonConvert.SerializeObject(options, new JsonSerializerSettings { ContractResolver = SmartContractResolver.Instance, Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }); output.PostElement.AppendHtmlLine(@$ "<script data-origin='EntityPicker'>$(function() {{ $('#{buttonId}').entityPicker({json}); }})</script>"); }