Error executing template "Designs/Dwsimple/eCom/Productlist/ProductListSearchResult.cshtml"
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
   at CallSite.Target(Closure , CallSite , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   at CompiledRazorTemplates.Dynamic.RazorEngine_fbef0b17944247b0a257ef9e7114aa51.<>c__DisplayClass1_0.b__0(TextWriter __razor_helper_writer) in D:\dynamicweb.net\solutions\HCT\mouldproDE.dw9.dynamicweb-cms.com\files\Templates\Designs\Dwsimple\eCom\Productlist\ProductListSearchResult.cshtml:line 168
   at CompiledRazorTemplates.Dynamic.RazorEngine_fbef0b17944247b0a257ef9e7114aa51.Execute() in D:\dynamicweb.net\solutions\HCT\mouldproDE.dw9.dynamicweb-cms.com\files\Templates\Designs\Dwsimple\eCom\Productlist\ProductListSearchResult.cshtml:line 444
   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.b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 2 3 @using System 4 @using System.Web 5 6 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 7 8 @using System.Text.RegularExpressions 9 @using System.Web 10 11 12 @functions{ 13 public class WrapMethods 14 { 15 //Gets the contrasting color 16 public static string getContrastYIQ(string hexcolor) 17 { 18 if (hexcolor != "") 19 { 20 hexcolor = Regex.Replace(hexcolor, "[^0-9a-zA-Z]+", ""); 21 22 int r = Convert.ToByte(hexcolor.Substring(0, 2), 16); 23 int g = Convert.ToByte(hexcolor.Substring(2, 2), 16); 24 int b = Convert.ToByte(hexcolor.Substring(4, 2), 16); 25 int yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000; 26 27 if (yiq >= 128) 28 { 29 return "black"; 30 } 31 else 32 { 33 return "white"; 34 } 35 } 36 else 37 { 38 return "black"; 39 } 40 } 41 42 43 //Truncate text 44 public static string Truncate (string value, int count, bool strip=true) 45 { 46 if (strip == true){ 47 value = StripHtmlTagByCharArray(value); 48 } 49 50 if (value.Length > count) 51 { 52 value = value.Substring(0, count - 1) + "..."; 53 } 54 55 return value; 56 } 57 58 59 //Strip text from HTML 60 public static string StripHtmlTagByCharArray(string htmlString) 61 { 62 char[] array = new char[htmlString.Length]; 63 int arrayIndex = 0; 64 bool inside = false; 65 66 for (int i = 0; i < htmlString.Length; i++) 67 { 68 char let = htmlString[i]; 69 if (let == '<') 70 { 71 inside = true; 72 continue; 73 } 74 if (let == '>') 75 { 76 inside = false; 77 continue; 78 } 79 if (!inside) 80 { 81 array[arrayIndex] = let; 82 arrayIndex++; 83 } 84 } 85 return new string(array, 0, arrayIndex); 86 } 87 88 //Make the correct count of columns 89 public static string ColumnMaker(int Col, string ScreenSize) 90 { 91 string Columns = ""; 92 93 switch (Col) 94 { 95 case 1: 96 Columns = "col-"+ScreenSize+"-12"; 97 break; 98 99 case 2: 100 Columns = "col-"+ScreenSize+"-6"; 101 break; 102 103 case 3: 104 Columns = "col-"+ScreenSize+"-4"; 105 break; 106 107 case 4: 108 Columns = "col-"+ScreenSize+"-3"; 109 break; 110 111 default: 112 Columns = "col-"+ScreenSize+"-3"; 113 break; 114 } 115 116 return Columns; 117 } 118 119 120 private string Custom(string firstoption, string secondoption) 121 { 122 if (firstoption == "custom") 123 { 124 return secondoption; 125 } 126 else 127 { 128 return firstoption; 129 } 130 } 131 } 132 } 133 134 135 136 137 138 139 @helper GetProductListSearch(dynamic Loop, int ColMD = 4, int ColSM = 2, int ColXS = 1) 140 { 141 int Count = 0; 142 143 string ColumnsMD = WrapMethods.ColumnMaker(ColMD, "md"); 144 string ColumnsSM = WrapMethods.ColumnMaker(ColSM, "sm"); 145 string ColumnsXS = WrapMethods.ColumnMaker(ColXS, "xs"); 146 147 var deviceType = Dynamicweb.Frontend.PageView.Current().Device.ToString(); 148 int TruncateSymbols = 0; 149 150 var pagedata = new System.Collections.Generic.Dictionary<String, Object>(); 151 Pageview.Area.Item.SerializeTo(pagedata); 152 153 string ProdPageId = (new System.Text.RegularExpressions.Regex(@"\d+")).Match(pagedata["ProductsPageId"].ToString()).Value; 154 155 var productList = new Dictionary<string, ProductItem>(); 156 157 foreach (var productItem in Loop) 158 { 159 var productId = productItem.GetString("Ecom:Product.ID"); 160 var groupId = productItem.GetString("Ecom:Product.PrimaryOrFirstGroupID"); 161 var image = productItem.GetString("Ecom:Product.ImageSmall.Default.Clean"); 162 163 if (!productList.ContainsKey(productId)) 164 { 165 var product = Dynamicweb.Ecommerce.Services.Products.GetProductById(productId, "", productItem.GetString("Ecom:Product.LanguageID")); 166 var productLink = "/Default.aspx?ID=" + ProdPageId + "&GroupID=" + groupId + "&ProductID=" + productId; 167 168 var newProductItem = new ProductItem 169 { 170 Area = Pageview.Area.Name, 171 Id = productId, 172 Name = System.Web.HttpUtility.JavaScriptStringEncode(product.Name), 173 Number = product.Number, 174 Price = product.Price.PriceWithVATFormatted, 175 Image = image, 176 GroupId = product.PrimaryGroupId, 177 ShortDesc = product.ShortDescription, 178 Link = productLink 179 }; 180 181 if (Pageview.Area.Name == "UK - Ecommerce") 182 { 183 newProductItem.LongDesc = productItem.GetString("Ecom:Product:Field.NAVProductEnglish"); 184 } 185 else if (Pageview.Area.Name == "DK - Ecommerce") 186 { 187 newProductItem.LongDesc = productItem.GetString("Ecom:Product:Field.NAVProductDanish"); 188 }; 189 190 productList.Add(productId, newProductItem); 191 } 192 } 193 194 if (productList.Count < 1) 195 { 196 <div class="alert alert-info"> 197 <h4 id="NoProductFound"> 198 <i class="fa fa-exclamation-circle" aria-hidden="true"></i>&nbsp; 199 <span>@Translate("No products found!")</span> 200 </h4> 201 </div> 202 } 203 204 foreach (var product in productList.Values) 205 { 206 string prodID = product.Id; 207 208 string GroupID = product.GroupId; 209 210 211 if (deviceType == "Desktop") 212 { 213 TruncateSymbols = 100; // 40 214 } 215 else if (deviceType == "Tablet") 216 { 217 TruncateSymbols = 100; //30 218 } 219 else 220 { 221 TruncateSymbols = 100; //50 222 } 223 224 <div class="productlist col-md-4 col-sm-6 col-xs-12 box"> 225 <div class="boxproduct wp-block product"> 226 <div class="listproductright"> 227 @{ 228 string ImgPath = "/Admin/Public/Getimage.ashx?width=300&amp;height=300&amp;compression=85&amp;Crop=5&amp;image="; 229 string DefImg = "&altFmImage_path=/Files/Images/Ecom/missing_image.gif"; 230 string image = ImgPath + product.Image + DefImg; 231 } 232 <a href="@product.Link" title="@product.Name"> 233 <figure style="" class="productfigure"> 234 <img alt="@product.Name" src="@image" class="img-responsive img-center"> 235 </figure> 236 </a> 237 </div> 238 <div class="listproductinfo"> 239 <div class="extracolumn"> 240 <h2 class="product-title"> 241 <a href="@product.Link" title="@product.Name">@WrapMethods.Truncate(product.Name, TruncateSymbols)</a> 242 </h2> 243 <div class="longproductdescription" style="height:auto;"> 244 <p>@WrapMethods.Truncate(product.LongDesc + "", 150)</p> 245 </div> 246 </div> 247 <div class="listproductleft wp-block-footer"> 248 <div class="productmorebr pull-right"> 249 <a href="@product.Link" class="btn btn-sm btn-dw-cart"><span>@Translate("Read more", "Read more")</span></a> 250 </div> 251 </div> 252 </div> 253 </div> 254 </div> 255 256 Count++; 257 258 if (Count == ColMD) 259 { 260 Count = 0; 261 } 262 } 263 } 264 265 @functions { 266 public class ProductItem 267 { 268 public string Area { get; set; } 269 public string Id { get; set; } 270 public string Name { get; set; } 271 public string Number { get; set; } 272 public string Price { get; set; } 273 public string Image { get; set; } 274 public string GroupId { get; set; } 275 public string ShortDesc { get; set; } 276 public string LongDesc { get; set; } 277 public string Link { get; set; } 278 } 279 } 280 281 @{ 282 string productviewtype = "box"; 283 string listView = "box"; 284 string BoxViewCustomClass = ""; 285 string activeClass = ""; 286 287 var haveselected = ""; 288 var deviceType = Dynamicweb.Frontend.PageView.Current().Device.ToString(); 289 290 291 292 293 listView = "box"; 294 295 BoxViewCustomClass = listView + "-view"; 296 297 activeClass = productviewtype == "box" ? "active" : ""; 298 299 var textSearchVal = ""; 300 if (!String.IsNullOrEmpty(HttpContext.Current.Request["VariantsTextSearch"])) 301 { 302 textSearchVal = HttpContext.Current.Request.QueryString.Get("VariantsTextSearch"); 303 } 304 305 var brand = ""; 306 if (!String.IsNullOrEmpty(HttpContext.Current.Request["Brand"])) 307 { 308 brand = HttpContext.Current.Request.QueryString.Get("Brand"); 309 } 310 311 string grouplink = ""; 312 313 if (!string.IsNullOrWhiteSpace(GetString("Ecom:ProductList:Page.GroupID"))) 314 { 315 grouplink = "/Default.aspx?ID=" + GetValue("Ecom:ProductList:Page.ID") + "&amp;GroupID=" + GetValue("Ecom:ProductList:Page.GroupID"); 316 } 317 else 318 { 319 grouplink = "/Default.aspx?ID=" + GetValue("Ecom:ProductList:Page.ID") + "&amp;eComQuery=" + GetValue("Ecom:ProductList:Search.Query"); 320 } 321 } 322 <script> 323 function getCookie(name) { 324 var pattern = RegExp(name + "=.[^;]*"); 325 matched = document.cookie.match(pattern); 326 327 if (matched) { 328 var cookie = matched[0].split('='); 329 return cookie[1]; 330 } 331 return false; 332 } 333 </script> 334 <style> 335 @@media(max-width:767px) { 336 h1.dw-section-title { 337 font-size: 25px 338 } 339 340 .productList .product-list-holder.box-view .productlist.col-sm-6, .product .product-list-holder.box-view .productlist.col-sm-6 { 341 width: 100%; 342 } 343 } 344 345 @@media (max-width:991px) { 346 h1.dw-section-title { 347 font-size: 22px 348 } 349 } 350 351 @@media(min-width:768px) { 352 .product-list.search .productlist.box .boxproduct { 353 min-height: 300px; 354 } 355 356 .productList .product-list-holder.box-view .productlist.col-sm-6, .product .product-list-holder.box-view .productlist.col-sm-6 { 357 width: 100%; 358 } 359 } 360 361 @@media(min-width:991px) { 362 .productList .product-list-holder.box-view .productlist.col-md-4, .product .product-list-holder.box-view .productlist.col-md-4 { 363 width: 50%; 364 } 365 366 .productList .product-list-holder.box-view .productlist.col-md-6, .product .product-list-holder.box-view .productlist.col-md-6 { 367 width: 100%; 368 } 369 } 370 371 @@media(min-width:1200px) { 372 .productList .product-list-holder.box-view .productlist.col-md-4, .product .product-list-holder.box-view .productlist.col-md-4 { 373 width: 33.3333%; 374 } 375 376 .productList .product-list-holder.box-view .productlist.col-md-6, .product .product-list-holder.box-view .productlist.col-md-6 { 377 width: 50%; 378 } 379 } 380 </style> 381 <div class="product-list search"> 382 <div class="row"> 383 <div class="col-xs-12 col-sm-6"> 384 <div class="row" id="CustomShowingRow"> 385 <div class="col-xs-12 col-sm-8 col-md-9 custom-title"> 386 @if (!string.IsNullOrWhiteSpace(GetString("Server:Request.ecomquery"))) 387 { 388 <h1 class="dw-section-title"><span>Searchresult for '@GetString("Server:Request.ecomquery")'</span></h1> 389 } 390 391 @if (string.IsNullOrWhiteSpace(GetString("Server:Request.ecomquery"))) 392 { 393 <h1 class="dw-section-title"> 394 <span> 395 @if (!string.IsNullOrWhiteSpace(GetString("Ecom:ProductList:Page.GroupName"))) 396 { 397 @GetString("Ecom:ProductList:Page.GroupName"); 398 } 399 else 400 { 401 string BrandName = !string.IsNullOrEmpty(HttpContext.Current.Request["Brand"]) ? "" + HttpContext.Current.Request.QueryString.Get("Brand") : ""; 402 403 if (!string.IsNullOrWhiteSpace(BrandName)) 404 { 405 <text>@Translate("Top matching products in", "Top matching products in")&nbsp;@BrandName</text> 406 } 407 else 408 { 409 <text>@Translate("Top matching products", "Top matching products")</text> 410 } 411 } 412 </span> 413 </h1> 414 } 415 </div> 416 417 @{ 418 var boxActive = " active"; 419 var listActive = ""; 420 if (listView == "details") 421 { 422 boxActive = ""; 423 listActive = " active"; 424 } 425 426 427 } 428 @if (!string.IsNullOrWhiteSpace(GetString("Ecom:Group.Description"))) 429 { 430 <div class="group-desc"> 431 @GetValue("Ecom:Group.Description") 432 </div> 433 } 434 </div> 435 436 437 <div class="row product-list-holder @BoxViewCustomClass"> 438 @if (listView == "details" && deviceType == "Desktop") 439 { 440 @GetProductListSearch(GetLoop("Products"), 4) 441 } 442 else 443 { 444 @GetProductListSearch(GetLoop("Products"), 4) 445 } 446 447 </div> 448 </div> 449 <div class="hidden-xs col-sm-1"> 450 451 </div> 452 <div class="col-xs-12 col-sm-5"> 453 454 @RenderSnippet("GroupsSearch") 455 456 </div> 457 </div> 458 459 </div> 460 461 462 463 @{ 464 465 466 bool IsDetailsView = listView == "details" ? true : false; 467 bool IsLoggedInUser = Dynamicweb.Core.Converter.ToBoolean(GetGlobalValue("Global:Extranet.UserName")); 468 string originalPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery; 469 470 471 } 472 473 474 <script> 475 476 function getCookie(cname) { 477 var name = cname + "="; 478 var decodedCookie = decodeURIComponent(document.cookie); 479 var ca = decodedCookie.split(';'); 480 for (var i = 0; i < ca.length; i++) { 481 var c = ca[i]; 482 while (c.charAt(0) == ' ') { 483 c = c.substring(1); 484 } 485 if (c.indexOf(name) == 0) { 486 return c.substring(name.length, c.length); 487 } 488 } 489 return ""; 490 } 491 492 function BoxView(el) { 493 document.cookie = "productviewtype=box"; 494 location.href = appendToQueryString("listView", "box"); 495 $('.custom-views .btn').removeClass("active"); 496 @*//el.classList.add("active");*@ 497 } 498 499 function ListView(el) { 500 document.cookie = "productviewtype=list"; 501 location.href = appendToQueryString("listView", "list"); 502 $('.custom-views .btn').removeClass("active"); 503 @*//el.classList.add("active");*@ 504 } 505 506 function DetailsView(el) { 507 document.cookie = "productviewtype=details"; 508 509 location.href = appendToQueryString("listView", "details"); 510 $('.custom-views .btn').removeClass("active"); 511 @*//el.classList.add("active");*@ 512 } 513 514 function SortProductsBy(sortcode) { 515 var Page = "@grouplink"; 516 517 document.cookie = "sortby=" + sortcode; 518 location.href = appendToQueryString("SortBy", sortcode); 519 } 520 521 appendToQueryString = function (param, val) { 522 var queryString = window.location.search.replace("?", ""); 523 var parameterListRaw = queryString == "" ? [] : queryString.split("&"); 524 var parameterList = {}; 525 for (var i = 0; i < parameterListRaw.length; i++) { 526 var parameter = parameterListRaw[i].split("="); 527 parameterList[parameter[0]] = parameter[1]; 528 } 529 parameterList[param] = val; 530 531 var newQueryString = "?"; 532 for (var item in parameterList) { 533 if (parameterList.hasOwnProperty(item)) { 534 newQueryString += item + "=" + parameterList[item] + "&"; 535 } 536 } 537 newQueryString = newQueryString.replace(/&$/, ""); 538 return location.origin + location.pathname + newQueryString; 539 }; 540 541 removeFromQueryString = function (param) { 542 var url = document.location.href; 543 var urlparts = url.split('?'); 544 545 if (urlparts.length >= 2) { 546 var urlBase = urlparts.shift(); 547 var queryString = urlparts.join("?"); 548 549 var prefix = encodeURIComponent(param) + '='; 550 var pars = queryString.split(/[&;]/g); 551 for (var i = pars.length; i-- > 0;) 552 if (pars[i].lastIndexOf(prefix, 0) !== -1) 553 pars.splice(i, 1); 554 url = urlBase + '?' + pars.join('&'); 555 window.history.pushState('', document.title, url); @*//added this line to push the new url directly to url bar .*@ 556 557 } 558 return url; 559 }; 560 @*APPLYING AN ACTIVE CLASS TO LIST VIEW BUTTONS - DO NOT REORDER THIS METHOD*@ 561 562 563 jQuery(document).ready(function ($) { 564 $('[data-toggle="tooltip"]').tooltip(); 565 }); 566 </script> 567 568 <script> 569 @if (!string.IsNullOrEmpty(HttpContext.Current.Request["q"])) 570 { 571 <text> $.cookie("productviewtype", "", { path: '/' });</text> 572 } 573 </script> 574