模板单轨ViewComponent [英] Template in monorail ViewComponent
问题描述
是否有可能与在虚拟机?
HTML内容块组件的模板我做的HTML了很多东西,并且希望在HTML驻留在.vm,而不是在codebehind。
下面是我已经得到了:
公共类TwoColumn:ViewComponent
{
公共覆盖无效渲染()
{
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
一
#结束
#columnTwo
二
#结束
#结束
twocolumn / default.vm(伪code):
< DIV CLASS =twoColumnLayout>
< DIV CLASS =columnOne>
#引用给columnOne
< / DIV>
< DIV CLASS =columnTwo>
#引用给columnTwo
< / DIV>
< / DIV>
您对基类ViewComponent的的RenderView
方法。你可以做的是使用写入就地视图成的TextWriter过载。
只要坚持这种方法在你的viewcomponent,你应该做的。
字符串RenderViewInPlace(字符串viewTemplate)
{
VAR缓冲=新的StringBuilder();
使用(VAR作家=新的StringWriter(缓冲))
{
的RenderView(MyView的,作家);
返回buffer.ToString();
}
}
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>
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
string RenderViewInPlace(string viewTemplate)
{
var buffer = new StringBuilder();
using (var writer = new StringWriter(buffer))
{
RenderView("myview", writer);
return buffer.ToString();
}
}
这篇关于模板单轨ViewComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!