Aside: I am using PublishedContentWrapped because the additional properties I'm adding to the viewModel should only have request scope, but if I extend the models builder object directly then that object has a longer scope and could be accessed by another user.
The documentation says I can access modelsBuilder properties like so:
// or using Modelsbuilder
@Model.ProductDescription
However ProductDescription is not a property on
public class MyProductViewModel : PublishedContentWrapped
My current workaround is to add a property to MyProductViewModel like so:
public ProductPage Page => (ProductPage)this.Unwrap() ;
Then in my view do this:
// or using Modelsbuilder
@Model.Page.ProductDescription
Is the documentation incorrect? or am I misreading it?
Hi Huw,
TLDR: I was misreading the docs, use PublishedContentWrapped if you're NOT using models builder.
DETAIL:
I should have Inherited from the models builder object, and created my inherited object on each request from within my controller using the constructor like so:
var viewModel = new MyProductViewModel(CurrentPage, new
PublishedValueFallback(_serviceContext, _variationContextAccessor))
{
CustomerInfo = GetCustomerInfo()
};
I was confused as to when would one use PublishedContentWrapped but after re-reading the docs, I think that is intended to be used if you're NOT using models builder.
Access ModelsBuilder properties in a view using a PublishedContentWrapped
Hi, I have a hijacking controller similarly to documented here: https://docs.umbraco.com/umbraco-cms/reference/routing/custom-controllers
Aside: I am using
PublishedContentWrapped
because the additional properties I'm adding to the viewModel should only have request scope, but if I extend the models builder object directly then that object has a longer scope and could be accessed by another user.The documentation says I can access modelsBuilder properties like so:
However ProductDescription is not a property on
public class MyProductViewModel : PublishedContentWrapped
My current workaround is to add a property to MyProductViewModel like so:
public ProductPage Page => (ProductPage)this.Unwrap() ;
Then in my view do this:
Is the documentation incorrect? or am I misreading it?
do you have this at the top of your view?
you can always access the values from your page node using the value method
To be able to use Modelsbuilder then your custom view should inherit from your Modelsbuilder Page model and not from publishcontentwrapped
Hi Huw,
TLDR: I was misreading the docs, use
PublishedContentWrapped
if you're NOT using models builder.DETAIL: I should have Inherited from the models builder object, and created my inherited object on each request from within my controller using the constructor like so:
I was confused as to when would one use
PublishedContentWrapped
but after re-reading the docs, I think that is intended to be used if you're NOT using models builder.is working on a reply...