一把umbraco - 渲染的.Net用户控件(ASCX)用剃刀宏(Umbraco - Rende

2019-09-17 09:13发布

我有一把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)' -->

有任何想法吗?

Answer 1:

<umbraco:Macro runat="server" language="cshtml">@{

HtmlTextWriter writer = new HtmlTextWriter(this.Output);
var navigation = new umbraco.presentation.templateControls.Macro();

navigation.Alias = "Navigation";
navigation.MacroAttributes.Add("ulclass", "art-vmenu");
navigation.MacroAttributes.Add("level", 2);

navigation.RenderControl(writer);   }</umbraco:Macro>

尝试这样的事情。 它为我...我已经做了导航宏。 要知道,虽然你的变量应该在TOLOWER给予,如果使用帽,该参数不会来通过。



Answer 2:

在一把umbraco 4.10+要调用剃刀脚本中宏,使用方法:

@ Umbraco.RenderMacro( “macroNameHere”,新的{propertyName1 = CurrentPage.pageProperty}))



Answer 3:

尝试是这样的:

@Html.Raw(umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"SuggestionBox\" />", Model.Id))


文章来源: Umbraco - Render .Net User Control (ascx) macro with Razor