I'm trying to render a Contour form from inside of my own Razor macro but keep getting a nul reference exception. The same form works on pages using the existing Razor macro directly so not sure what I'm doing wrong?
I get a "The type or namespace name 'RenderMacro' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)" exception on doing that - perhaps because the siite is not in "MVC Mode"? The site is not MVC and so not sure what the implications of turning this feature on are?
As a last resort I might try the third party package however it would be good to know why this can't work out of the box, the code was copied directly from the MvcRenderContourForm.cshtml razor file and that works fine..
It's a bit more complicated than that as the macro will be accepting multiple form guids and using some internal logic to make the selections which is why I am trying to render the macro directly from within my own. Guessing I'm going to have to perhaps rethink this however it would be good if this could be considered for a future release?
Ran into the same problem here - trying to render the Razor macro from Webforms. I wasn't sure if there was some RenderMacro helper we can use in Webforms (other than umbraco.library.RenderMacroContent -- will that work?). So I was able to work around it like so:
@helper RenderContourForm(string formGuid) { string action = "ContourForm"; string controller = "FormRender"; string formtoken = "UmbracoContourForm"; // We need to build up an object with the formGuid, as the controller doesn't seem to read it from the formGuid variable but the latest parameter dynamic p = new ContourFormParameters(); p.formGuid = formGuid;
Sorry I am trying to do that but I do not understand what I need to do, where I need to create that code.
I am trying to convert this code to MVC umbraco 7.3 with PartialView:
Render Form from within own Razor File
I'm trying to render a Contour form from inside of my own Razor macro but keep getting a nul reference exception. The same form works on pages using the existing Razor macro directly so not sure what I'm doing wrong?
I've simplified the call to the following:
Am I missing something? Contour 3 and Umbraco 4.11.4.
Thanks, Simon
Stack trace in case it helps:
Did you try to call it as a macro inside your razor macro? Something like this:
More info here: http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx
Jeroen
I get a "The type or namespace name 'RenderMacro' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)" exception on doing that - perhaps because the siite is not in "MVC Mode"? The site is not MVC and so not sure what the implications of turning this feature on are?
Cheers, Simon
My example is for MVC so that won't work. You could try the Razor Components package to render the macro instead: http://our.umbraco.org/projects/website-utilities/razor-components
Jeroen
As a last resort I might try the third party package however it would be good to know why this can't work out of the box, the code was copied directly from the MvcRenderContourForm.cshtml razor file and that works fine..
Thanks
Comment author was deleted
Well the macro needs the param formGuid it's fetches it from there, the string formGuid isn't used
So I have to use a RenderMacro helper of some sort? Is there any way of me adding the parameter inline?
Thanks Tim
Comment author was deleted
No you just need to add a param to your macro
It's a bit more complicated than that as the macro will be accepting multiple form guids and using some internal logic to make the selections which is why I am trying to render the macro directly from within my own. Guessing I'm going to have to perhaps rethink this however it would be good if this could be considered for a future release?
Simon
Ran into the same problem here - trying to render the Razor macro from Webforms. I wasn't sure if there was some RenderMacro helper we can use in Webforms (other than umbraco.library.RenderMacroContent -- will that work?). So I was able to work around it like so:
ContourFormParameters is just a quick class I stuck in /App_Code/ so we have an object to assign the formGuid parameter to:
Then you can just call @RenderContourForm("") to insert the form.
Hope this might help someone. Should there be an easier way to dynamically insert a Razor form from an "old Razor" file (macroScripts)?
-Tom
Hi Tom!
Sorry I am trying to do that but I do not understand what I need to do, where I need to create that code. I am trying to convert this code to MVC umbraco 7.3 with PartialView:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Umbraco.Forms.Mvc.Bridge.Html;
@{
}
Could you guide me a bit more?
Thank you
is working on a reply...