Posted on 03/04/2019 13:59:21
Why do you need ProductDescriptionViewModel? Why don't you just call the Translate method directly?
The ProductDescriptionViewModel in your example is not a view model. It inherits from RazorTemplateBase, so it represents a razor template instance.
You should avoid instantiating razor templates inside another razor template like this. Razor templates are instantiated by Dynamicweb when needed.
Anyway...
To make your code work you can change ProductDescriptionViewModel to a simple class and add a constructor which takes an instance of a RazorTemplateBase.
ProductDescriptionViewModel can then call the Translate method on that RazorTemplateBase...
public class ProductDescriptionViewModel
{
public ProductDescriptionViewModel(RazorTemplateBase<RazorTemplateModel<Template>> templateBase)
{
this.TemplateBase = templateBase;
}
private RazorTemplateBase<RazorTemplateModel<Template>> TemplateBase { get; }
public string TranslateProductDescription {
get {
return TemplateBase.Translate("(product) Description", "Product Description");
}
}
}
Use it in your razor template like this...
@{
var productDescriptionFooter = new ProductDescriptionViewModel(this);
}
<text>@productDescriptionFooter.TranslateProductDescription</text>
ProductDescriptionViewModel is still not a view model, but more like a helper class that doesn't help that much :)
Best regards,
Morten