Developer forum

Forum » Swift » Publications: Productfields template error

Publications: Productfields template error

Anouk van der Veer
Reply

Hi all,

I've been playing around with the new Publications. Since recent the Publication_ProductFields template stopped working, showing the following error on my datasheet:

Error executing template "Designs/Publications/Paragraph/Publication_ProductFields/FieldValue.cshtml"

System.InvalidCastException: Unable to cast object of type 'Dynamicweb.Frontend.ParagraphViewModel' to type 'Dynamicweb.Ecommerce.ProductCatalog.FieldValueViewModel'.
   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.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()
 
  1     @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Ecommerce.ProductCatalog.FieldValueViewModel>
@using Dynamicweb.Frontend
@using Dynamicweb.Ecommerce.ProductCatalog
@{
var hideUnitsOfMeasure = Convert.ToBoolean(Pageview.CurrentParagraph.Item["HideUnitsOfMeasure"]);
if (Model.IsList() && Model.GetList() is List<FieldOptionValueViewModel> listValues) {
foreach (var field in listValues)
{
if (field.IsColor() && field.GetColor() is ColorViewModel colorModel)
{
string hexColor = colorModel.Hex;
<span class="dwp-color-box" style="background-color: @hexColor" title="@hexColor"></span>
} else {
<span>@field.Value</span>
}
}
}
else 
{
if (Model.IsLink() && Model.GetLink() is LinkViewModel linkModel)
{
<span>
<a href="@linkModel.Url">@linkModel.Url</a>
</span>
}
else if (Model.IsColor() && Model.GetColor() is ColorViewModel colorModel)
{
string hexColor = colorModel.Hex;
<span class="dwp-color-box" style="background-color: @hexColor" title="@hexColor"></span>
}
else if (Model.IsFile() && Model.GetFile() is FileViewModel fileModel)
{
var file = fileModel;
<a href="@file.Path" download>@file.Name</a>
}
else
{
var value = hideUnitsOfMeasure ? Model.Value : Model.GetValueWithUnits();
value = value.ToString().ToLower() == "true" ? Translate("Yes") : value;
value = value.ToString().ToLower() == "false" ? Translate("No") : value;
<span>@value</span>
}
}
}

I don't think i've made any changes before it stopped working. Could it be a bug, related to an update of DW10?

Kind regards,
Anouk


Replies

 
Merethe Vrå Andersen Dynamicweb Employee
Merethe Vrå Andersen
Reply
This post has been marked as an answer

Hi,

Thank you for reporting this. It seems to DW10 related. I have bugged it in 19936.

BR,
Merethe Vrå Andersen, QA

Votes for this answer: 1

 

You must be logged in to post in the forum