10

In ASP.NET MVC I could parse Razor scripts like this:

string template = "It is @DateTime.Now.ToString()";
string result = Razor.Parse(template);

But this static doesn't exist in core.

Also I've read this post, but in my case the view code is a string, so I can't use the find or get view methods from the ICompositeViewEngine.

Any advice on how to get a view string parsed in core?

Community
  • 1
  • 1
Boas Enkler
  • 12,264
  • 16
  • 69
  • 143
  • Possible duplicate of [Render Razor view to string in ASP.NET 5](http://stackoverflow.com/questions/30362156/render-razor-view-to-string-in-asp-net-5) – Toddams Jun 29 '16 at 16:58
  • 1
    Possible duplicate of [Render Razor View to string in ASP.NET Core](http://stackoverflow.com/questions/32558941/render-razor-view-to-string-in-asp-net-core) – Karl-Johan Sjögren Jul 24 '16 at 12:21

1 Answers1

5

I've already answered the question Here

Today I've finished with my library that can solve your problem. You can use it out of ASP.NET as it has no dependencies on it

This is how you can use it

string template = "It is @DateTime.Now.ToString()";
string result = new LightRazorEngine().ParseString(template);

More: https://github.com/toddams/RazorLight

Community
  • 1
  • 1
Toddams
  • 1,489
  • 15
  • 23