单轨 ViewComponent 中的模板
是否可以在 vm 中为块组件提供一个包含 html 内容的模板?
我在 html 中做了很多事情,并且希望 html 驻留在 .vm 中,而不是代码隐藏中。
这是我得到的:
public class TwoColumn : ViewComponent
{
public override void Render()
{
RenderText(@"
<div class='twoColumnLayout'>
<div class='columnOne'>");
// Context.RenderBody();
Context.RenderSection("columnOne");
RenderText(@"
</div>
<div class='columnTwo'>");
Context.RenderSection("columnTwo");
RenderText(@"
</div>
</div>
");
}
}
这是我想要得到的: pageWithTwoColumns.vm:
#blockcomponent(TwoColumn)
#columnOne
One
#end
#columnTwo
Two
#end
#end
twocolumn/default.vm(伪代码):
<div class="twoColumnLayout">
<div class="columnOne">
#reference-to-columnOne
</div>
<div class="columnTwo">
#reference-to-columnTwo
</div>
</div>
Is it possible to have a template with html content in vm for a block component?
I'm doing a lot of stuff in html, and want the html reside in a .vm, not in codebehind.
Here is what i've got:
public class TwoColumn : ViewComponent
{
public override void Render()
{
RenderText(@"
<div class='twoColumnLayout'>
<div class='columnOne'>");
// Context.RenderBody();
Context.RenderSection("columnOne");
RenderText(@"
</div>
<div class='columnTwo'>");
Context.RenderSection("columnTwo");
RenderText(@"
</div>
</div>
");
}
}
Here is what i want to get:
pageWithTwoColumns.vm:
#blockcomponent(TwoColumn)
#columnOne
One
#end
#columnTwo
Two
#end
#end
twocolumn/default.vm (pseudocode):
<div class="twoColumnLayout">
<div class="columnOne">
#reference-to-columnOne
</div>
<div class="columnTwo">
#reference-to-columnTwo
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ViewComponent 的基类上有 RenderView 方法。您可以做的是使用将视图就地写入 TextWriter 的重载。
只需将此方法粘贴到您的视图组件中即可完成
You have the
RenderView
method on the base class of the ViewComponent. what you can do is use the overload that writes the view in-place into a TextWriter.just stick this method in your viewcomponent and you should be done
我终于找到了使用 Ken 建议的 StringWriter 技术的解决方案,但方法不同。它不是 RenderView,而是 RenderSection
模板:
如果您不介意的话,我会建议单轨列车的功能。
如果能够像这样引用视图模板中的部分,那就太好了:
I have finally found a solution using Ken's suggested StringWriter technique, but with different method. It's not RenderView, it's RenderSection
template:
I would suggest a feature for monorail, if you don't mind.
It would be great to be able to reference the section from view template like this: