Cannot bind source type Umbraco.Web.Models.PartialViewMacroModel
I am trying to create a macro so that I can easily insert my ContactForm.cshtml partial page anywhere in a content section.
No matter how much I try the result is usually the same, either I get stuck with the page displaying "Macro alias: InsertContactForm" where the partial page should render.
I am using a seperate webservice to process the request, so I have javascript that validates and sends the information. I am not using a controller or model.
I see this error:
Error loading Partial View (file: ~/Views/MacroPartials/InsertContactForm.cshtml). Exception: Umbraco.Web.Mvc.ModelBindingException: Cannot bind source type Umbraco.Web.Models.PartialViewMacroModel to model type Umbraco.Web.Models.RenderModel.
at Umbraco.Web.Mvc.RenderModelBinder.ThrowModelBindingException(Boolean sourceContent, Boolean modelContent, Type sourceType, Type modelType)
at Umbraco.Web.Mvc.RenderModelBinder.BindModel(Object source, Type modelType, CultureInfo culture)
at Umbraco.Web.Mvc.UmbracoViewPage`1.SetViewData(ViewDataDictionary viewData)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName)
at ASP._Page_Views_MacroPartials_InsertContactForm_cshtml.Execute() in d:\home\site\wwwroot\Views\MacroPartials\InsertContactForm.cshtml:line 1
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult)
at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, IPublishedContent content)
at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, INode node)
at umbraco.macro.LoadPartialViewMacro(MacroModel macro)
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
My InsertContactForm.cshtml (under macro partials)
I am still learning, perhaps macro's are not meant to be used this way. Regardless I figured that the point of a macro was to be reusable, and in this case the contact form is not intended to be reused.
So what I did instead was delete the macro stuff and simply created a template and added it to the optional templates on my landing page document type and selected the new template for use on that specific page. In the template I included an Html.Partial which added my partial .cshtml page to the end of the document.
A late reply, but hopefully helpful for anyone else who experiences this problem.
Instead of using @inherits Umbraco.Web.Mvc.UmbracoTemplatePage, as this is what's causing the conflict between this and Umbraco.Web.Models.PartialViewMacroModel
If you leave out the 'inherits' bit all together, you can initialise
var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
and call
umbracoHelper.TypedContent(xxxx) instead of Umbraco.TypedContent(xxxx) ... for instance
umbracoHelper gives you access to all the same functionality as you get by inheriting the model through @inherits
Cannot bind source type Umbraco.Web.Models.PartialViewMacroModel
I am trying to create a macro so that I can easily insert my ContactForm.cshtml partial page anywhere in a content section.
No matter how much I try the result is usually the same, either I get stuck with the page displaying "Macro alias: InsertContactForm" where the partial page should render.
I am using a seperate webservice to process the request, so I have javascript that validates and sends the information. I am not using a controller or model.
I see this error:
My InsertContactForm.cshtml (under macro partials)
My ContactForm.cshtml (under partials) if it helps
I am still learning, perhaps macro's are not meant to be used this way. Regardless I figured that the point of a macro was to be reusable, and in this case the contact form is not intended to be reused.
So what I did instead was delete the macro stuff and simply created a template and added it to the optional templates on my landing page document type and selected the new template for use on that specific page. In the template I included an Html.Partial which added my partial .cshtml page to the end of the document.
A late reply, but hopefully helpful for anyone else who experiences this problem.
Instead of using @inherits Umbraco.Web.Mvc.UmbracoTemplatePage, as this is what's causing the conflict between this and Umbraco.Web.Models.PartialViewMacroModel
If you leave out the 'inherits' bit all together, you can initialise
and call
umbracoHelper.TypedContent(xxxx) instead of Umbraco.TypedContent(xxxx) ... for instance
umbracoHelper gives you access to all the same functionality as you get by inheriting the model through @inherits
is working on a reply...