Developer forum

Forum » Templates » Cart view model not set

Cart view model not set

Rasmus Andersen
Reply

Hi Dynamicweb,

I am getting the error from the attached screenshot when trying to use a CartViewModel.
I am on Dynamicweb 9.3.5.

Is there something I am missing?

Best regards,
Rasmus

 

cartviewmodel.png

Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

Hi Rasmus,

Cart templates do not support view models (yet), but you can use the Cart property when rendering a page like this...

@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
<!DOCTYPE html>
<html>
<head>
    <title>@Model.Title</title>
</head>
<body>
    <div>
        @if (Model.Cart != null)
        {
            <h2>Cart</h2>
            <p>@Model.Cart.TotalProductsCount</p>
        }

        <div>
            @Model.Placeholder("content")
        </div>
    </div>
</body>
</html>

 

See https://doc.dynamicweb.com/template-tags/introduction/concept/viewmodels

Best regards,
Morten

Votes for this answer: 1
 
Rasmus Andersen
Reply

Hi Morten,

We are using view models just like you describe.
Thanks for the explanation.

Best regards,
Rasmus Westfall Andersen

 
Tin Ma Ma
Reply

Hi Morten,

When I click this link http://doc.dynamicweb.com/template-tags/introduction/concept/razor-templates-viewmodels, it shows 404 page.
May I know where can I find the Cart View Models.

Regards,

Tin Ma Ma

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

You can find it under template tags documentation.
See ViewModels.

Too see details about individual view models you can perform a search in the API section for "ViewModel".

Best regards,
Morten

 

You must be logged in to post in the forum