Error executing template "Designs/Swift/eCom/ProductCatalog/VariantSelector.cshtml"
System.InvalidCastException: Unable to cast object of type 'Dynamicweb.Ecommerce.ProductCatalog.ProductListViewModel' to type 'Dynamicweb.Ecommerce.ProductCatalog.ProductViewModel'.
   at RazorEngine.Templating.TemplateBase`1.SetModel(Object model)
   at RazorEngine.Templating.TemplateBase.SetData(Object model, DynamicViewBag viewbag)
   at RazorEngine.Templating.RazorEngineCore.CreateTemplate(ICompiledTemplate template, Object model, DynamicViewBag viewbag)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   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<ProductViewModel> 2 @using Dynamicweb.Frontend 3 @using Dynamicweb.Rendering 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 6 @{ 7 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 8 { 9 Dynamicweb.Context.Current.Items["ProductDetails"] = Model; 10 } 11 else 12 { 13 Dynamicweb.Context.Current.Items.Add("ProductDetails", Model); 14 } 15 16 string viewType = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("ViewType")) ? Dynamicweb.Context.Current.Request.Form.Get("ViewType") : string.Empty; 17 bool quantitySelector = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("QuantitySelector")) ? Convert.ToBoolean(Dynamicweb.Context.Current.Request.Form.Get("QuantitySelector")) : false; 18 19 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 20 if (!url.Contains("LayoutTemplate")) 21 { 22 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 23 } 24 25 //Basic ParagraphViewModel setting 26 var paragraphViewModel = new ParagraphViewModel() 27 { 28 ID = 123456789 29 }; 30 31 string buttonLayout = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("ButtonLayout")) ? Dynamicweb.Context.Current.Request.Form.Get("ButtonLayout") : string.Empty; 32 string buttonAspectRatio = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("ButtonAspectRatio")) ? Dynamicweb.Context.Current.Request.Form.Get("ButtonAspectRatio") : string.Empty; 33 34 var parms = new Dictionary<string, object>(); 35 parms.Add("ButtonLayout", buttonLayout); 36 parms.Add("ButtonAspectRatio", buttonAspectRatio); 37 } 38 39 @if (Model.VariantInfo?.VariantInfo != null) 40 { 41 if (viewType == "ModalContent") 42 { 43 bool neverOutOfStock = Model.NeverOutOfstock; 44 bool isDiscontinued = Model.Discontinued; 45 bool isStockType = Model.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Stock; 46 47 double? stepQty = Model.PurchaseQuantityStep > 0 ? Model.PurchaseQuantityStep : 1; 48 double? minQty = Model.PurchaseMinimumQuantity > 0 ? Model.PurchaseMinimumQuantity : 1; 49 double? valueQty = minQty > stepQty ? minQty : stepQty; 50 bool setMaxQty = isStockType && !neverOutOfStock; 51 double? maxQty = setMaxQty ? Model.StockLevel : null; 52 53 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 54 string disableAddToCart = (Model.StockLevel <= 0) ? "disabled" : ""; 55 disableAddToCart = isDiscontinued ? "disabled" : disableAddToCart; 56 disableAddToCart = neverOutOfStock && !isLazyLoadingForProductInfoEnabled ? "" : disableAddToCart; 57 disableAddToCart = string.IsNullOrEmpty(Model.VariantId) ? "disabled" : disableAddToCart; 58 59 60 <div class="modal-header"> 61 <h5 class="modal-title">@Model.Name</h5> 62 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 63 </div> 64 <div class="modal-body"> 65 @RenderPartial("Components/VariantSelector.cshtml", paragraphViewModel, parms) 66 </div> 67 <div class="modal-footer"> 68 <form method="post" action="@url"> 69 <input type="hidden" name="redirect" value="false"> 70 <input type="hidden" name="ProductName" value="@Model.Name"> 71 <input type="hidden" name="ProductVariantName" value="@Model.VariantName"> 72 <input type="hidden" name="ProductId" value="@Model.Id"> 73 <input type="hidden" name="VariantId" value="@Model.VariantId" id="VariantIdField_@Model.Id"> 74 <input type="hidden" name="ProductReferer" value="variant_selector"> 75 <input type="hidden" name="cartcmd" value="add"> 76 77 <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code"> 78 <input type="hidden" name="ProductReferer" value="variant_selector_modal"> 79 <input type="hidden" name="ProductPrice" value="@PriceViewModelExtensions.ToStringInvariant(Model.Price)"> 80 81 <template class="js-step-quantity-warning"> 82 <div class="modal-header"> 83 <h1 class="modal-title fs-5">@Translate("The quantity is not valid")</h1> 84 </div> 85 <div class="modal-body"> 86 @Translate("Please select a quantity that is dividable by") @stepQty 87 </div> 88 </template> 89 90 <template class="js-min-quantity-warning"> 91 <div class="modal-header"> 92 <h1 class="modal-title fs-5">@Translate("The product could not be added to the cart")</h1> 93 </div> 94 <div class="modal-body"> 95 @Translate("The quantity is not valid. You must buy at least") @Model.PurchaseMinimumQuantity 96 </div> 97 </template> 98 99 @if (quantitySelector) 100 { 101 <div class="flex-fill input-group input-primary-button-group d-flex flex-row"> 102 <input id="Quantity_@(Model.Id)_@Model.VariantId" name="Quantity" value="@valueQty" step="@stepQty" min="@minQty" max="@maxQty" class="form-control swift_quantity-field" style="max-width: 100px" type="number" onkeydown="swift.Cart.UpdateOnEnterKey(event)" @disableAddToCart> 103 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary flex-fill js-add-to-cart-button" title="@Translate("Add to cart")" id="AddToCartButton@(Model.Id)_@Pageview.CurrentParagraph.ID" @disableAddToCart>@Translate("Add to cart")</button> 104 105 <div class="invalid-feedback d-none"> 106 @Translate("Please select a quantity that is dividable by") @stepQty 107 </div> 108 109 </div> 110 <label for="Quantity_@(Model.Id)_@Model.VariantId" class="visually-hidden">@Translate("Quantity")</label> 111 } 112 else 113 { 114 <input id="Quantity_@(Model.Id)_@Model.VariantId" name="Quantity" value="@valueQty" type="hidden" @disableAddToCart> 115 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary flex-fill js-add-to-cart-button" title="@Translate("Add to cart")" id="AddToCartButton@(Model.Id)_@Pageview.CurrentParagraph.ID" @disableAddToCart>@Translate("Add to cart")</button> 116 } 117 </form> 118 </div> 119 } 120 else 121 { 122 @RenderPartial("Components/VariantSelector.cshtml", paragraphViewModel) 123 } 124 125 <script type="module"> 126 swift.VariantSelector.init(); 127 </script> 128 } 129