Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Stuart Paterson 58 posts 229 karma points
    Jun 15, 2022 @ 10:14
    Stuart Paterson
    0

    Vendr - Rendering Product Details

    Hey,

    I'm in the middle of a site build and I've been watching Paul's walkthrough's for installing Vendr (great videos as always, will be purchasing him a coffee or 5). I've created my doc types and properties for Store, Product etc and installed Vendr.

    In the walkthroughs Paul is using Modelsbuilder in LiveAppData mode but the site I've been building out is currently in PureLive. I've taken the Vendr DemoStore code though to try and get an idea of rendering my product details but I've hit a snag.

    My Product page content is built out by rendering multiple partial views (UmbracoViewPage) and only one of those partials contains the pricing info I want to pull through from my Vendr product.

    Error on Product page is "The source is a ModelsBuilder type, but the view model is not".

    Any help would be appreciated, when I kicked off this web project I had spotted Paul's Vendr walkthroughs and thought perfect, but as it's built using Modelsbuilder it's kind of thrown me having always just worked in PureLive mode.

    Cheers, Stuart

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 15, 2022 @ 11:42
    Matt Brailsford
    0

    Hi Stuart

    No problem. Can you share any error messages complete with stack trace and potentially your markup for the partial you created and I can see what I can suggest 👍🏻

  • Stuart Paterson 58 posts 229 karma points
    Jun 15, 2022 @ 12:35
    Stuart Paterson
    0

    Hi Matt,

    So on my product page/view I'm rendering this partial:

    Html.Partial("/Views/Partials/MediaLayers/_CoursePricingLayer.cshtml");

    This is the stack trace when I rendering a the product page:

    [ModelBindingException: Cannot bind source content type Umbraco.Web.PublishedModels.Course to model type ICSLearnV8.core.Models.ProductPage. The source is a ModelsBuilder type, but the view model is not. The application is in an unstable state and should be restarted.]
       Umbraco.Web.Mvc.ContentModelBinder.ThrowModelBindingException(Boolean sourceContent, Boolean modelContent, Type sourceType, Type modelType) in D:\a\1\s\src\Umbraco.Web\Mvc\ContentModelBinder.cs:159
       Umbraco.Web.Mvc.ContentModelBinder.BindModel(Object source, Type modelType) in D:\a\1\s\src\Umbraco.Web\Mvc\ContentModelBinder.cs:94
       Umbraco.Web.Mvc.UmbracoViewPage`1.SetViewData(ViewDataDictionary viewData) in D:\a\1\s\src\Umbraco.Web\Mvc\UmbracoViewPageOfTModel.cs:152
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +99
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
       Umbraco.Web.Mvc.ProfilingView.Render(ViewContext viewContext, TextWriter writer) in D:\a\1\s\src\Umbraco.Web\Mvc\ProfilingView.cs:25
       System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) +277
       System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +91
       System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName) +32
       ASP._Page_Views_Course_cshtml.Execute() in C:\Users\stuartp\source\Workspaces\ICSLearnV8_Vendr_Test\ICSLearnV8_Vendr_Test\ICSLearnV8_Vendr_Test\Views\Course.cshtml:34
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +256
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
       Umbraco.Web.Mvc.ProfilingView.Render(ViewContext viewContext, TextWriter writer) in D:\a\1\s\src\Umbraco.Web\Mvc\ProfilingView.cs:25
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +290
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
       System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +198
       System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100
       System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
       System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
       System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller) +13
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
       System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
       System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +576
       System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +132
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163
    

    Here's the top of the product page view -

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<object>
    @using ICSLearnV8.core;
    @using Vendr.Core.Models;
    @using ICSLearnV8.core.Models;
    @using Umbraco.Core.Models.PublishedContent;
    @using System.Web.Mvc.Html;
    @using Umbraco.Web;
    @using ICSLearnV8.Models;
    @using ICSLearnV8.Helpers;
    @using ICSLearnV8.Controllers.SurfaceControllers;
    @{
        Layout = "_Layout.cshtml";
        IPublishedContent CurrentPage = UmbracoContext.PublishedRequest.PublishedContent;
        var homePage = CurrentPage.AncestorOrSelf("home");
        var siteSetting = homePage.DescendantsOrSelfOfType("siteSettings").First();
        var courseController = new CourseActionsController();
        var facStyle = CurrentPage.Value("facultyStyle");
        var heroItems = CurrentPage.Value<IEnumerable<IPublishedElement>>("heroItems");
    
    }
    
    @Html.Partial("~\\Views\\Partials\\_RenderHeroItems.cshtml")
    
    @{
        <section class="course-wrap">
            <div class="container">
                <div class="row">
                    <div class="col-lg-8 padding-bottom course-copy">
                        @{
                            if (CurrentPage.Value<bool>("displayAnchor"))
                            {
                                @Html.Partial("~\\Views\\Partials\\MediaLayers\\_AnchorLayer.cshtml")
                            }
                            Html.Partial("/Views/Partials/MediaLayers/_CoursePricingLayer.cshtml");
    

    Here's the beginning of the _CoursePricingLayer.cshtml -

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ProductPage>
    @using ICSLearnV8.core;
    @using Vendr.Core.Models;
    @using ICSLearnV8.core.Models;
    @using ICSLearnV8.Helpers;
    @using ICSLearnV8.Controllers.SurfaceControllers;
    @using Umbraco.Core.Models.PublishedContent;
    @using Umbraco.Web;
    @using NPoco.fastJSON;
    
    @{
        IPublishedContent CurrentPage = UmbracoContext.PublishedRequest.PublishedContent;
        var store = Model.Value<StoreReadOnly>("store", fallback: Fallback.ToAncestors);
        var addedProductReference = TempData["addedProductReference"]?.ToString();
        var renderForm = false;
        var homePage = CurrentPage.AncestorOrSelf("home");
        var siteSetting = homePage.DescendantsOrSelfOfType("siteSettings").First();
        var courseController = new CourseActionsController();
        var mediaLayer = Model;
        var facStyle = CurrentPage.Value("facultyStyle");
        var layerTitle = !string.IsNullOrEmpty(mediaLayer.Value<string>("layerTitle")) ? mediaLayer.Value<string>("layerTitle") : mediaLayer.Name;
        var courseCode = CurrentPage.Value<string>("courseCode");
    
        var isAmp = false;
        if (Request.RawUrl.Contains("amp=1"))
        { isAmp = true; }
    
        <section id="@(layerTitle.ToLower().Replace(" ", "-"))" class="section spacer-30">
            <div class="row bg-white">
                <div class="col-lg-6 col-md-6 m-auto">
                    <div class="ics-popover d-flex">
                        <div class="col-12 d-flex justify-content-center align-items-center">
                            <img src="/media/738552/price-tag-large.png" alt="price tag icon" loading="lazy">
                            <h2 class="@facStyle-prim-font mb-0 course-price">£121/month <span class="block">interest-free</span></h2>
                        </div>
                        <div id="popover-content" style="display:none">
                            This is an estimate based on the current exchange rate.<br>
                            Course fees will be charged in GBP.<br><br>
                            <div class="row">
                                <div class="col-4">
                                    <strong>Monthly:</strong><br>£121/month
                                </div>
                                <div class="col-4">
                                    <strong>Deposit:</strong><br>£129
                                </div>
                                <div class="col-4">
                                    @Html.Hidden("productReference", Model.GetProductReference())
                                    <p><strong>Total Price</strong><br><span>£@(Model.CalculatePrice())</span></p>
                                </div>
    

    To confirm the site is running Umbraco V8.18 with Vendr v 2.21 installed...

    Thanks, Stuart

Please Sign in or register to post replies

Write your reply to:

Draft