Error executing template "Designs/Swift/eCom/ProductCatalog/ProductSearchDropdownResponse.cshtml"
System.ArgumentNullException: Value cannot be null.
Parameter name: source
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
   at CompiledRazorTemplates.Dynamic.RazorEngine_940e43f33d9c49edb385bb5b4d4f3e1d.Execute() in D:\dynamicweb.net\Solutions\Co3\espritduvin.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\eCom\ProductCatalog\ProductSearchDropdownResponse.cshtml:line 120
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits ViewModelTemplate<ProductListViewModel> @using Dynamicweb.Rendering @using Dynamicweb.Ecommerce.ProductCatalog @{ string searchTerm = string.Empty; string layout = Dynamicweb.Context.Current.Request["SearchLayout"] != null ? Dynamicweb.Context.Current.Request["SearchLayout"].ToString() : "field"; string itemPadding = layout == "icon" ? "px-1" : "px-1"; string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/"; if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request["eq"])) { searchTerm = Dynamicweb.Context.Current.Request["eq"].Trim(); } Dictionary<string, string> suggestions = new Dictionary<string, string>(); } @functions{ string Highlight(string input, string textToHighlight) { if (string.IsNullOrEmpty(textToHighlight)) { return input; } input = fixHtmlEncoding(input.ToLower()); foreach (string term in textToHighlight.Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries)) { input = input.Replace(term, "</mark>" + term + "<mark>"); } return "<span class=\"js-suggestion flex-fill text-break\" data-suggestion-value=\"\"><mark>" + input + "</mark></span>"; } string ProductNameHighlight(string input, string textToHighlight) { if (string.IsNullOrEmpty(textToHighlight)) { return input; } input = fixHtmlEncoding(input.ToLower()); foreach (string term in textToHighlight.Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries)) { input = input.Replace(term, "<mark>" + term + "</mark>"); } return "<span class=\"js-suggestion flex-fill text-break\" data-suggestion-value=\"\">" + input + "</span>"; } string fixHtmlEncoding(string input) { if (input.IndexOf("&") > 0) { if (input.IndexOf(" ", input.IndexOf("&")) > 0) { input = input.Replace(" ", "; "); } else { input += ";"; input = System.Net.WebUtility.HtmlDecode(input); } } return input; } string escape(string input) { return Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(fixHtmlEncoding(input)); } void AddSuggestion(string suggestion, string group, Dictionary<string, string> suggestions) { suggestion = suggestion.ToLower(); if (!suggestions.ContainsKey(suggestion)) { suggestions.Add(suggestion, group); } } } @if (Model.SpellCheckerSuggestions != null && Model.SpellCheckerSuggestions.Any()) { List<string> validSuggestions = new List<string>(); foreach (string suggestion in Model.SpellCheckerSuggestions) { if (!validSuggestions.Contains(suggestion)) { validSuggestions.Add(suggestion); } } if (validSuggestions.Count == 0) { foreach (string suggestion in Model.SpellCheckerSuggestions) { if (!validSuggestions.Contains(suggestion)) { validSuggestions.Add(suggestion); } } } if (validSuggestions.Count > 0) { foreach (string suggestion in validSuggestions.Take(5)) { AddSuggestion(suggestion, "Did you mean", suggestions); <li class="dropdown-item d-flex flex-row align-items-center py-2 px-0 text-wrap"> <span class="dropdown-item-search-icon d-flex align-items-center justify-content-center" aria-hidden="true" onclick="swift.Typeahead.selectSuggestion(this.parentElement);"></span> <span class="flex-fill" onclick="swift.Typeahead.selectSuggestion(this.parentElement);">@Highlight(suggestion, searchTerm)</span> <span class="dropdown-item-arrow-icon d-flex d-lg-none align-items-center justify-content-center" aria-hidden="true" onclick="swift.Typeahead.setSuggestion(this.parentElement);"></span> </li> } } } @if (Model.FacetGroups.Any()) { var maxSuggestions = 5; foreach (var facetGroup in Model.FacetGroups) { foreach (var facetItem in facetGroup.Facets) { var facetOptionCount = facetItem.OptionCount; var optionActiveCount = facetItem.OptionActiveCount; var facetOptionResultTotalCount = facetItem.OptionResultTotalCount; var queryParameter = facetItem.QueryParameter; var template = facetItem.RenderType; var maxValue = facetItem.MaximumFacetValue; var minValue = facetItem.MinimumFacetValue; List<FacetOptionViewModel> validOptions = new List<FacetOptionViewModel>(); foreach (var facetOption in facetItem.Options.OrderByDescending(option => option.Count)) { if (searchTerm != null && validOptions.Count < maxSuggestions) { validOptions.Add(facetOption); } } if (validOptions.Count > 0) { <li class="text-wrap"> <h6 class="dropdown-header ps-5 pe-3 py-3">@facetItem.Name</h6> </li> foreach (var facetOption in validOptions) { AddSuggestion(facetOption.Label, facetItem.Name, suggestions); <li class="dropdown-item @itemPadding" onclick="swift.Typeahead.selectSuggestion(this);" data-param="@queryParameter" data-paramvalue="@facetOption.Value"> @Highlight(facetOption.Label, searchTerm) <div class="">@facetOption.Count</div> </li> } } } } } @if (Model.Products.Count() > 0) { var validSuggestions = new List<ProductViewModel>(); string label = Translate("Products"); if (Model.Group != null) { label = Model.Group.Name; } foreach (var product in Model.Products) { if (searchTerm != null && product.Name.IndexOf(searchTerm, StringComparison.InvariantCultureIgnoreCase) >= 0 || true) { AddSuggestion(product.Name, label, suggestions); validSuggestions.Add(product); } } if (validSuggestions.Count > 0) { <li class="text-wrap"> <h6 class="dropdown-header ps-5 pe-3 py-3">@label</h6> </li> foreach (var suggestion in validSuggestions) { var defaultGroupId = suggestion.PrimaryOrDefaultGroup.Id; var selectedDetailsPage = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(defaultGroupId).Meta.PrimaryPage; selectedDetailsPage = !string.IsNullOrEmpty(selectedDetailsPage) ? selectedDetailsPage : null; //If selectedDetailsPage is null, the data-selected-details-page parameter will not be rendered to the finished markup if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request["defaultpdpId"])) { selectedDetailsPage = $"Default.aspx?ID={Dynamicweb.Context.Current.Request["defaultpdpId"]}"; } string productDetailLink = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl($"{selectedDetailsPage}&GroupID={defaultGroupId}&ProductID={suggestion.Id}"); <li class="dropdown-item d-flex flex-row flex-lg-row-reverse align-items-center text-wrap px-0 text-wrap" onclick="swift.Typeahead.selectSuggestion(this);" data-param="ProductId" data-selected-details-page="@productDetailLink" data-paramvalue="@suggestion.Id"> <span aria-hidden="true" class="d-lg-none dropdown-item-search-icon d-flex align-items-center justify-content-center"></span> @ProductNameHighlight(suggestion.Name + " - " + suggestion.Number, searchTerm) <img class="mx-2" src="/admin/public/getimage.ashx?image=@Dynamicweb.Context.Current.Server.UrlEncode(suggestion.DefaultImage.Value)&width=32&height=32&format=webp&Crop=5&fillcanvas=true" height="32" width="32" alt="@suggestion.Name"> </li> } } } @if (!string.IsNullOrEmpty(searchTerm)) { if (Model.TotalProductsCount > 0) { <li class="dropdown-item text-center text-decoration-underline text-wrap @itemPadding" onclick="swift.Typeahead.selectSuggestion(this);"> @Translate("View all") @Model.TotalProductsCount @Translate("products for")<mark> "<span class="js-suggestion">@searchTerm</span>"</mark> </li> } else { <li class="dropdown-item text-center text-decoration-underline text-wrap @itemPadding" onclick="swift.Typeahead.selectSuggestion(this);" style="cursor: pointer;"> @Translate("We have no results for")<mark> "<span class="js-suggestion">@searchTerm</span>"</mark> </li> } <li class="py-2"></li> }