Razor做邮件内容动态生成器

来源:互联网 发布:中卫云计算2018,130 编辑:程序博客网 时间:2024/06/08 21:39
Razor做邮件内容动态生成器也可以用来做静态页面生成器方法一:var template = "Hello @Model.Name! Welcome to Razor!";var viewData = new { Name = "World" });var result = Razor.Parse(template, viewData);方法二:var stringWriter = new StringWriter();var viewContext = new ViewContext(controllerContext, view, viewData, TempData, stringWriter);view.Render(viewContext, stringWriter);var result = stringWriter.ToString();参考:http://blog.csdn.net/dyllove98/article/details/8709512示例:Markdown mk = new Markdown();string content = mk.Transform(article.Content);//markdown转换htmlvar model = new{    ID=  article.ID,    Title = article.Title,    Content = content,    Link = article.Link,    WriteTime = article.WriteTime,    Description = article.Description,    Author = article.Author,};string text = Engine.Razor.RunCompile(WebSource.Instance.DetailTemplate, "templateDetail", null, model);//razor转换htmlstring outputFilePath = string.Format("{0}/output/{1}", AppDomain.CurrentDomain.BaseDirectory, article.Link);Directory.CreateDirectory(outputFilePath);//创建目录File.WriteAllText(outputFilePath + "/index.html", text);//写入文件

参考:
http://www.cnblogs.com/JsonYang/p/4517764.html
http://www.cnblogs.com/loui/p/MvcTemplate.html

0 0