逃脱Asp.Net MVC框架/枷锁,使用Razor视图引擎(4)
var result = instance.Result;
return result;
}
最后,看看视图模板类,一个基类和一个泛型基类,后者用于前类型Model
[csharp]
public abstract class TemplateBase
{
public string Layout { get; set; }
public UrlHelper Url { get; set; }
public Func<string> RenderBody { get; set; }
public string Path { get; internal set; }
public string Result { get { return Writer.ToString(); } }
protected TemplateBase()
{
}
public TextWriter Writer
{
get
{
if(writer==null)
{writer = new StringWriter();
}
return writer;
}
set {
writer = value;
}
}
private TextWriter writer;
public void Clear() {
Writer.Flush();
}
public virtual void Execute() { }
public void Write(object @object) {
if (@object == null) {
return;
相关新闻>>
- 发表评论
-
- 最新评论 更多>>