Razor inline Macro in usercontrol and using data from SQL datasource
Hi,
In short the question is: How do I use a SQL datasource field (called UmbracoID) inside the inline-razor macro?
I have created an usercontrol in VB, and now I would like to use some inline razor macroing, but I can't seem to find any examples on how to use an external parameter (such as SQL datasource) inside the macro.
Here is my present code (If i hardcode the ID it works):
Basically I have a database which contains a table with all my departments. In this table I have added an integer field containing the node-number for each department relative to my umbraco-pages. What I wanna do is to use this int, so that I can use the "serviceBeregnerAabningstider" field from Umbraco.
The following list shows the Public Properties from the
Control. By checking the Properties and click the "Save Properties" button at
the bottom, umbraco will create the corresponding Macro Elements.
System.Web.HttpParseException
(0x80004005): Code blocks are not supported in this context. --->
and it goes on :-)
Any pointers would be greatly appreciated (and yes I am a noob), so even if it is obvious please help me :-)
Razor inline Macro in usercontrol and using data from SQL datasource
Hi,
In short the question is: How do I use a SQL datasource field (called UmbracoID) inside the inline-razor macro?
I have created an usercontrol in VB, and now I would like to use some inline razor macroing, but I can't seem to find any examples on how to use an external parameter (such as SQL datasource) inside the macro.
Here is my present code (If i hardcode the ID it works):
Basically I have a database which contains a table with all my departments. In this table I have added an integer field containing the node-number for each department relative to my umbraco-pages. What I wanna do is to use this int, so that I can use the "serviceBeregnerAabningstider" field from Umbraco.
The error i am recieving is this:
Error reading usercontrols/Serviceberegner/Serviceberegner.ascx
The following list shows the Public Properties from the Control. By checking the Properties and click the "Save Properties" button at the bottom, umbraco will create the corresponding Macro Elements.
System.Web.HttpParseException (0x80004005): Code blocks are not supported in this context. --->
and it goes on :-)
Any pointers would be greatly appreciated (and yes I am a noob), so even if it is obvious please help me :-)
/Regards
Jimmy
Could you to to add RenderEvent="PreRender" to the macro. By default it runs preinit and the Eval("UmbracoID") might not be ready yet.
Jeroen
I tried this:
<umbraco:Macro runat="server" language="cshtml" RenderEvent="PreRender">
@Library.NodeById(<%#Eval("UmbracoID")%>).serviceBeregnerAabningstider
</umbraco:Macro>
And it still tells me that code block is not allowed.Have I done i correctly?
/Regards
Jimmy
Maybe you should create a separate razor macro file and pass the value as a parameter to that: http://our.umbraco.org/documentation/reference/templating/macros/razor/using-macro-parameters
Also make sure that your Razor macro file still has the RenderEvent="PreRender".
Jeroen
is working on a reply...