Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Razor string in ASP.NET core

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?

like image 910
Boas Enkler Avatar asked Jun 29 '16 12:06

Boas Enkler


1 Answers

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

like image 106
Toddams Avatar answered Oct 07 '22 08:10

Toddams