【发布时间】:2016-04-27 18:07:14
【问题描述】:
想象一下这个场景......
@helper TabTest()
{
using (Html.BeginPortlet())
{
<strong>hello</strong>
}
}
如果我在 Razor 文件中调用它,那么它渲染得很好。
@TabTest()
输出:<div class="portlet"><strong>hello</strong></div>
如果我使用另一个助手调用它...例如:@Html.RenderBootstrapTabContent(TabTest()) 那么渲染就不一样了。
输出:
<div class="portlet"></div>
<strong>hello</strong>
这只是一个粗略的例子,我已经删除了冗余代码以简化。我认为这与管道的编写方式有关,但我认为无法修复它。
我已经阅读了有关 viewcontexts 和 textwriters 的内容,但不知道它们将如何应用在这里。
帮手:
public static MvcHtmlString RenderBootstrapTabContent(this HtmlHelper helper, HelperResult content)
{
return content.ToHtmlString();
}
BeginPortlet 方法是自定义的,与BeginForm 非常相似,并使用IDisposable 接口。
如何解决这个奇怪的错误?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-4 razor