I am new to Umbraco and I want to create a document type for forms in Umbraco and I am having issues. I want to create a reusable document type for all the forms. At the moment, I created a FormType document type and I am creating partial views for all my forms and then placing macros in the forms that create from. However, I am now getting an error that the form cannot be rendered. Can someone please help me with the best practice for creating a reusable document type for all my forms?
What does the error you're getting specifically say? And could you perhaps post some screendumps that displays what you're doing? Just want to make sure I get what you're up to.
Sorry, my explanation was confusing. On the FormType document type, I created a property called content. So when I create any page from that document type, I put in the macro that contains the form partial view. Now on the front end, I just get an error saying "Error loading partial view XXXX.cshtml". No specific error about why the view is breaking and cannot load. Even the console in the browser is blank. So my question is more about, is this a good way to create forms or can someone suggest a better way so that I can create one document type and multiple forms from that document type in Umbraco.
015-02-18 19:14:37,784 [9] WARN umbraco.macro - [Thread 11] Error loading partial view macro (View: ~/Views/MacroPartials/Register.cshtml). Exception: System.InvalidOperationException: The model item passed into the dictionary is of type 'Umbraco.Web.Models.PartialViewMacroModel', but this dictionary requires a model item of type 'MVCUmbracoFreelance.Models.Register'. at System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) at System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) at System.Web.Mvc.WebViewPage`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 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)
I have seen this error before I know how to resolve it in a normal scenario but in this case I created a document type called "FormType". In the document type, I creaed a property called Content of type Richtext Editor. In this field I insert a macro above. This is where I am getting this error. Is there a way I can pass in the model or is there a better way to do this?
Aaah, good you managed to figure it out and thanks for sharing so it's easy for others to figure out what worked for you if they have the same issue. You should mark your last post as the solution so others can go straight to it :)
Create a document type for forms
Hi,
I am new to Umbraco and I want to create a document type for forms in Umbraco and I am having issues. I want to create a reusable document type for all the forms. At the moment, I created a FormType document type and I am creating partial views for all my forms and then placing macros in the forms that create from. However, I am now getting an error that the form cannot be rendered. Can someone please help me with the best practice for creating a reusable document type for all my forms?
Thanks
Hi Mohammed and welcome to our :)
What does the error you're getting specifically say? And could you perhaps post some screendumps that displays what you're doing? Just want to make sure I get what you're up to.
/Jan
Sorry, my explanation was confusing. On the FormType document type, I created a property called content. So when I create any page from that document type, I put in the macro that contains the form partial view. Now on the front end, I just get an error saying "Error loading partial view XXXX.cshtml". No specific error about why the view is breaking and cannot load. Even the console in the browser is blank. So my question is more about, is this a good way to create forms or can someone suggest a better way so that I can create one document type and multiple forms from that document type in Umbraco.
Thanks for your help
Hi Mohammed
Ok, could you try having a look in the /App_Data/Logs file? It should contain a stack trace about the error somewhere. Please post that in here :)
/Jan
Hi,
Sorry, its on my other machine, will post it as soon as I get home.
Thanks Jan
Hi,
Here is the Stacktrace from the log file:
015-02-18 19:14:37,784 [9] WARN umbraco.macro - [Thread 11] Error loading partial view macro (View: ~/Views/MacroPartials/Register.cshtml). Exception: System.InvalidOperationException: The model item passed into the dictionary is of type 'Umbraco.Web.Models.PartialViewMacroModel', but this dictionary requires a model item of type 'MVCUmbracoFreelance.Models.Register'.
at System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value)
at System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary)
at System.Web.Mvc.WebViewPage`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 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)
I have seen this error before I know how to resolve it in a normal scenario but in this case I created a document type called "FormType". In the document type, I creaed a property called Content of type Richtext Editor. In this field I insert a macro above. This is where I am getting this error. Is there a way I can pass in the model or is there a better way to do this?
Thank you
Hi Mohammed
Ok, what does your macro code look like? You probably just need to inherit the model in the macro I guess.
/Jan
Hi Jan
My partial view looks like:
@model MVCUmbracoFreelance.Models.RegisterFreelancer
@using (Html.BeginUmbracoFormAccountSurfaceController>("Register", null, new { @id = "registerform", @class = "form-gray-fields validate" }, FormMethod.Post))
{
}
In Umbraco, I create a macro and use this partial view above.
Thanks Jan
Hi Jan,
I managed to resolve the issue by changing the code a little. I found this article that helped: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/57275-Partial-Macro-View-issue-(Custom-Model-and-RenderModel)
Thanks a lot for your help. I will definitely post again if I come across any other issues.
Hi Mohammed
Aaah, good you managed to figure it out and thanks for sharing so it's easy for others to figure out what worked for you if they have the same issue. You should mark your last post as the solution so others can go straight to it :)
/Jan
is working on a reply...