How can I visualize the appearance of a razor for a string without depending on the context of the controller?

How can I visualize the appearance of a razor for a string without depending on the context of the controller?

All the examples I've seen are related to passing the render helper class to the ControllerContext. However, I do not want the context context of the controller, since I want the rendered string to be generated inside the service.

+5
source share
1 answer

RazorEngine seems to do exactly what you are looking for:

string template = "Hello @Model.Name! Welcome to Razor!";
string result = Razor.Parse(template, new { Name = "World" });
+9
source

All Articles