AI OnAI Off
Hi Jon,
With a content block template, if you use default block controller then you only need to create a partial view template with name convension {BlockTypeName}.cshtml and the view model type must be that block type. If you create your own controller then you need to point to correct partial view template. In your example, there are 2 ways to fix your problem:
1. Change this line
return this.PartialView(viewModel);
to
return this.PartialView("XFormBlock",viewModel);
2. Change view name and create parent folder as default MVC like: Views/XFormBlock/Index.cshtml
The Error is:
The model item passed into the dictionary is of type 'Castle.Proxies.XFormBlockProxy', but this dictionary requires a model item of type 'XXX.Models.ViewModels.XFormPageViewModel'.
at System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value)
at System.Web.Mvc.ViewDataDictionary.set_Model(Object value)
at System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary)
at System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData)
at System.Web.Mvc.WebViewPage.set_ViewData(ViewDataDictionary value)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at EPiServer.Web.Mvc.ViewExtensions.Render[T](IView view, ViewEngineResult viewEngineResult, ViewContext context, TextWriter writer, T data)
at EPiServer.Web.Mvc.MvcContentRenderer.HandleRenderTemplateWithViewEngine(HtmlHelper helper, IContentData contentData, TemplateModel templateModel)
at EPiServer.Web.Mvc.MvcContentRenderer.Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
at XXX.Business.Rendering.ErrorHandlingContentRenderer.Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
Here is my code:
XFormBlock.cshtml
XFormBlock.cs
XFormBlockController.cs
XFormPageViewModel.cs
Can you let me know if you can see where I am going wrong?
Many thanks
Jon