我在 Umbraco 中有一个非常复杂的剃须刀脚本,我希望在其中的某个时候在其中渲染一个宏。
被称为 SuggestionBox 的宏实际上是一个用户控件 (.ascx),传统上它在模板上使用
<umbraco:macro Alias="SuggestionBox" language="cshtml" runat="server"></umbraco:macro>
但是现在我需要从剃刀脚本中调用它,所以我尝试了;
@Html.Raw(umbraco.library.RenderMacroContent("SuggestionBox", Model.Id))
也:
@RenderPage("SuggestionBox")
没有运气,因为我确定我错误地使用了这些。
如果页面包含在母版页中,我在某处读到它可能是不可行的。
如果我像往常一样将它添加到模板中,它会起作用:
<umbraco:macro Alias="EventsRenderer" language="cshtml" runat="server"></umbraco:macro>
<div class="talkingPointPanel">
<h3><umbraco:Item field="talkingPoinstSuggestionText" runat="server"></umbraco:Item></h3>
<umbraco:macro Alias="SuggestionBox" language="cshtml" runat="server"></umbraco:macro>
</div>
EventsRenderer 在哪里呈现理想情况下应该包含 SuggestionBox 的页面。
使用
@Html.Raw(umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"SuggestionBox\" />", Model.Id))
给我这个错误:
<!-- Error generating macroContent: 'System.Web.HttpException (0x80004005): HtmlForm cannot render without a reference to the Page instance. Make sure your form has been added to the control tree.
at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at umbraco.presentation.templateControls.Macro.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at umbraco.library.RenderMacroContent(String Text, Int32 PageId)' -->
有任何想法吗?