Refer:https://github.com/antaris/razorengine
Microsoft's Template editor.
Install-package Razorengine
usingRazorengine;usingrazorengine.templating;stringTemplatePath =@"D:\Google drive\learn\tdd\tdd\views\email\index.cshtml";stringTemplate = System.IO.File.ReadAllText (TemplatePath);//read template content from a filestringTemplatekey ="Demo";//take a name .DynamicViewBag =NewDynamicviewbag ();//Create ViewBagViewbag.value = -; TEMPLATEVM VMS=NewTEMPLATEVM {name ="kknd"};//Create a view model//Edit Templatestringresult =Engine.Razor.RunCompile (template, Templatekey, VM. GetType (), VM, (dynamicviewbag) ViewBag//Strong Turn);//Replace valueVM =NewTEMPLATEVM {name ="zzzz"};viewbag.value=99999; result=Engine.Razor.RunCompile (template, Templatekey, VM. GetType (), VM, (dynamicviewbag) viewBag);
Pending research tests:
-Cache
-Get the template
-MVC can use all the work?
Razorengine Study Notes