Lucio Flores
2020-11-29T23:53:49Z

RazorEngineUseExample.cs

| static void Main(string[] args)
| {
|
| var config = new TemplateServiceConfiguration();
| config.CachingProvider = new DefaultCachingProvider(t => { });
| config.DisableTempFileLocking = true;
| var service = RazorEngineService.Create(config);
| string razorTemplate = File.ReadAllText("Template.cshtml");
| string templateName = "helloWorld";
| bool isCached = service.IsTemplateCached(templateName, typeof(object));
| service.Compile(razorTemplate, templateName); //razor template
| var htmlString = isCached ? service.Run(templateName, null, new { Name = "CachedTemplate" }) : service.RunCompile(templateName, null, new { Name = "Not cached templated" });
| Console.WriteLine(htmlString);
| }

Template.cshtml

|
|
|
|
|
| Welcome
|
|
| Hello @Model.Name!
|
|