Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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?

share|improve this question
    
Possible duplicate of Render Razor view to string in ASP.NET 5 – Toddams Jun 29 at 16:58
1  
Possible duplicate of Render Razor View to string in ASP.NET Core – Karl-Johan Sjögren Jul 24 at 12:21

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.