码迷,mamicode.com
首页 > 其他好文 > 详细

CommonHelper

时间:2015-07-01 09:45:13      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

 public static string RanderHtml(string templateName, object data)
        {
            VelocityEngine vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));
            vltEngine.Init();           
            VelocityContext vltContext = new VelocityContext();
            vltContext.Put("Data", data );

            Template vltTemplate = vltEngine.GetTemplate(templateName);
            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);
            string html = vltWriter.GetStringBuilder().ToString();
            return html;
        }

 

CommonHelper

标签:

原文地址:http://www.cnblogs.com/lushixiong/p/4612280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!