Note that there are some explanatory texts on larger screens.

plurals
  1. POOrchard throws 'The model item passed into the dictionary is of type Part but this dictionary requires a model of type VM
    primarykey
    data
    text
    <p>This is an editor for WebShop Global Settings. I needed to extend the editor with a ViewModel. It worked fine before I started but now crashes with the above error when it's invoked. What am I doing wrong?</p> <p>Here's the driver:</p> <pre><code>public class WebShopSettingsPartDriver : ContentPartDriver&lt;WebShopSettingsPart&gt; { private readonly ISiteService _siteService; private readonly IWebshopSettingsService _webshopSettings; protected override string Prefix { get { return "WebShopSettings"; } } private const string shapeName = "Parts_WebShopSettings_Edit"; private const string templateName = "Parts/WebShopSettings"; public WebShopSettingsPartDriver(IWebshopSettingsService webshopSettings, ISiteService siteService) { _webshopSettings = webshopSettings; _siteService = siteService; } protected override DriverResult Editor(WebShopSettingsPart part, dynamic shapeHelper) { var settings = _siteService.GetSiteSettings().As&lt;WebShopSettingsPart&gt;(); var model = new WebShopSettingsVM { WebShopSettings = settings, ShippingProducts = _webshopSettings.ShippingProductRecords() }; return ContentShape(shapeName, () =&gt; shapeHelper.EditorTemplate(TemplateName: templateName, Model: model, Prefix: Prefix)).OnGroup("WebShop"); } } </code></pre> <p>}</p> <p>Here is the Handler:</p> <pre><code> public class WebShopSettingsPartHandler : ContentHandler { public WebShopSettingsPartHandler(IRepository&lt;WebShopSettingsRecord&gt; repository) { T = NullLocalizer.Instance; Filters.Add(new ActivatingFilter&lt;WebShopSettingsPart&gt;("Site")); Filters.Add(StorageFilter.For(repository)); OnGetContentItemMetadata&lt;WebShopSettingsPart&gt;((context, part) =&gt; context.Metadata.EditorGroupInfo.Add(new GroupInfo("WebShop"))); } } </code></pre> <p>And here is the first line of the View (which is in Views\EditorTemplates\Parts\WebShopSettings.cshtml):</p> <pre><code>@model Cascade.WebShop.ViewModels.WebShopSettingsVM </code></pre> <p>The Placement.ini file has the following entry:</p> <pre><code>&lt;Place Parts_WebShopSettings_Edit="Content:0" /&gt; </code></pre> <p>Here is the ViewModel:</p> <pre><code>public class WebShopSettingsVM { public IEnumerable&lt;ShippingProductRecord&gt; ShippingProducts{ get; set; } [Required] public int? ShippingProductRecordId { get; set; } public WebShopSettingsPart WebShopSettings { get; set; } // Expose all the properties of the Part directly on the VM [Required] public string AdministratorEmailAddress { get { return WebShopSettings.AdministratorEmailAddress; } set { WebShopSettings.AdministratorEmailAddress = value; } } [Required] public string ContinueShoppingUrl { get { return WebShopSettings.ContinueShoppingUrl; } set { WebShopSettings.ContinueShoppingUrl = value; } } // and so on... } </code></pre> <p>After Bertrand's suggestion below I updated the View to:</p> <pre><code>@using Cascade.WebShop.ViewModels @using Cascade.WebShop.Models @{ var vm = Model.Model as WebShopSettingsVM; } &lt;fieldset&gt; &lt;legend&gt;@T("Webshop")&lt;/legend&gt; &lt;div&gt; &lt;label for="@Html.FieldIdFor(x=&gt;vm.AdministratorEmailAddress)"&gt;@T("Administrator email address")&lt;/label&gt; @Html.TextBoxFor(x=&gt;vm.AdministratorEmailAddress, new { @class = "textMedium" }) @Html.ValidationMessage("AdministratorEmailAddress", "*") ... </code></pre> <p>Insights and suggestions greatly appreciated -- I simply can't see what's wrong.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload