I have a macro usercontrol that contains a typical asp.net form. Is it possible to have a razor script that has some logic in it to insert this macro depending on some condition. If so what is the code for adding a macro to a razor script?
You can't have a UserControl macro on a Razor Macro (unless it doesn't have any postbacks). Only the other way around works. I had the same problem and simply put the usercontrol in an iframe and added that to the razor macro.
This package will let you call one macro from inside another. Not sure if a user controll would work with postbacks though. (You would have to make sure that caching is turned off on both macros if there are dynamic display or postbacks.)
What about razor macros? I have a razor macro where I'd like to insert a partial view, I already tried @RenderPage() adn @Html.Partial() with no success. What would be the recommended way (if any) to do this?
Hmm there might be some confusion here. What version of Umbraco are you using? In Umbraco there are 2 versions of Razor. One is the "old" Razor macro which was introduced in 4.7 and one is the "new" Razor MVC which is used when you create a view template in 4.11. All the examples I mentioned are about the "old" Razor macro. I don't know if it will work on "new" Razor MVC.
I'm using 4.11.1. I already have some partial views in "/Views/Partials", which I can render inside my templates (razor templates), using @Html.Partial(). My idea is to have a macro that will through some logic, "decide" which partial view to render. That's the reason I'm trying to have something similar to @Html.Partial() inside a macro.
The reason is to allow the content editor to insert this functionality (or content) on a given page using TyneMCE and the only way I can think of it is through a macro.
I am using the @Library.RenderMacro("~/macroScripts/scriptFile.cshtml",new{Property1="value",Prop2="value2"})
Now i did this with one macro that uses razor script and it is fine, but I have another macro that has a .net user control behind, it looks like when I use the parameters they are not being picked up.
It looks like it simply renders the html but does not fire the code behind, I put some debugging in the form_Load and nothing happened.
Insert Macro inside razor script
I have a macro usercontrol that contains a typical asp.net form. Is it possible to have a razor script that has some logic in it to insert this macro depending on some condition. If so what is the code for adding a macro to a razor script?
Hopefully this makes sense!!!
Cheers
I think this might be my answer http://our.umbraco.org/forum/developers/razor/23051-Razor-and-Macro
You can't have a UserControl macro on a Razor Macro (unless it doesn't have any postbacks). Only the other way around works. I had the same problem and simply put the usercontrol in an iframe and added that to the razor macro.
Jeroen
This package will let you call one macro from inside another. Not sure if a user controll would work with postbacks though. (You would have to make sure that caching is turned off on both macros if there are dynamic display or postbacks.)
https://github.com/tocsoft/Umbraco-Razor-Components
What about razor macros?
I have a razor macro where I'd like to insert a partial view, I already tried @RenderPage() adn @Html.Partial() with no success.
What would be the recommended way (if any) to do this?
You should use the Razor Components package like Jeremy said. Than you can do this to call a Razor macro inside another Razor macro:
Jeroen
Is it going to work even if I'm calling a partial view from "/Views/Partials"?
Hmm there might be some confusion here. What version of Umbraco are you using? In Umbraco there are 2 versions of Razor. One is the "old" Razor macro which was introduced in 4.7 and one is the "new" Razor MVC which is used when you create a view template in 4.11. All the examples I mentioned are about the "old" Razor macro. I don't know if it will work on "new" Razor MVC.
Jeroen
I'm using 4.11.1.
I already have some partial views in "/Views/Partials", which I can render inside my templates (razor templates), using @Html.Partial().
My idea is to have a macro that will through some logic, "decide" which partial view to render. That's the reason I'm trying to have something similar to @Html.Partial() inside a macro.
Why would you use a macro for that? Think it's good to read this blog: http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx. The chapter called "The power of the Partial View" is what you need I think.
Jeroen
The reason is to allow the content editor to insert this functionality (or content) on a given page using TyneMCE and the only way I can think of it is through a macro.
For now you can only use the "old" Razor macro in the RTE and I don't know how partial views work in there. In v6 it will be changed: https://groups.google.com/forum/#!msg/umbraco-dev/w4-cnlWDXTk/udLLflab10IJ
Jeroen
Man, I didn't even know they are already cooking a version 6.
Thanks for your help.
I am using the @Library.RenderMacro("~/macroScripts/scriptFile.cshtml",new{Property1="value",Prop2="value2"})
Now i did this with one macro that uses razor script and it is fine, but I have another macro that has a .net user control behind, it looks like when I use the parameters they are not being picked up.
It looks like it simply renders the html but does not fire the code behind, I put some debugging in the form_Load and nothing happened.
is working on a reply...