Render a macro from a macro container with MVC Razor
I have a macro that renders correctly with
@Umbraco.RenderMacro("pictureSlider")
in the template.
Now, I want the to choose a macro by using the Macro Container. My document type has the property with the Macro Container data type. In the page I select the "pictureSlider" macro.
But now what is the code to render the "pictureSlider" macro on the page?
In my case it was actually a bug on Umbraco Cloud / in Courier, because I had renamed the property alias on the composition, but after deploy of the changes, live environment still had the old alias.
http://issues.umbraco.org/issue/UAAS-493
So I ended up with the following:
@{
Guid g = new Guid(Model.Content.FormPicker.ToString());
Html.RenderAction("Render", "UmbracoForms", new { formId = g, mode = "form" });
}
Render a macro from a macro container with MVC Razor
I have a macro that renders correctly with
in the template.
Now, I want the to choose a macro by using the Macro Container. My document type has the property with the Macro Container data type. In the page I select the "pictureSlider" macro.
But now what is the code to render the "pictureSlider" macro on the page?
Your help would be much appreciated.
Thanking you in anticipation.
Roger
Hi Roger,
Try to use this snippet of code if you are running dynamic Razor
If you are using strongly typed Razor, you should use this syntax
Remember to change the "macroContainer" so it match your property alias on your document type.
Hope this helps,
/Dennis
Hi Dennis
Do you know how to render a Umbraco Forms picker via macro container using ModelsBuilder.
I have tried the following without any luck - actually
Model.Content.Form
doesn't seem to return a value for the picked macro container.However this does work:
/Bjarne
I have the same issue. I just ended up turning it into something strongly typed:
Where FormsViewer is the ModelsBuilder generated class and UmbracoForm is the Property.
In my case it was actually a bug on Umbraco Cloud / in Courier, because I had renamed the property alias on the composition, but after deploy of the changes, live environment still had the old alias. http://issues.umbraco.org/issue/UAAS-493
So I ended up with the following:
Thanks, Dennis.
That's fixed it!
Thanks to you guys, I'm having a good weekend.
Roger
is working on a reply...