RazorLight | Template engine based on Microsoft 's Razor parsing engine
kandi X-RAY | RazorLight Summary
kandi X-RAY | RazorLight Summary
Use Razor to build templates from Files / EmbeddedResources / Strings / Database or your custom source outside of ASP.NET MVC. No redundant dependencies and workarounds in pair with excellent performance and .NET Standard 2.0 and .NET Core 3.0 support.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of RazorLight
RazorLight Key Features
RazorLight Examples and Code Snippets
Community Discussions
Trending Discussions on RazorLight
QUESTION
I'm trying to render some simple HTML/Bootstrap tables side by side but getting stuck at this even after trying the previous solutions offered from on here. I'm sure it's something simple but I'm new to this, so any help would be appreciated.
I have two lists in my model, of equal size, that I would like to display beside each other. The correct data is being displayed, but I simply cannot get them to render alongside each other:
//Layout
...ANSWER
Answered 2021-Jan-22 at 11:23You have not added bootstrap class row. Wrap your code around div with class="row"
QUESTION
I'm working on building a POC where I compile an index.cshtml using razorlight then generate a pdf using dinktopdf, so far I got that part working fine.
Next, using vuejs and vue-qrcode, I was able to add a qrcode to the page where qr-code tag is converted into canvas and the qrcode is being displayed.
Now, the issue I'm running into is that during the generation of the pdf, vue-qrcode isn't being compiled into regular html (it should be a canvas tag) and nothing is being added to the pdf.
The solution is in the following Repository
page = await engine.CompileRenderAsync(path, model);
shows the full string of the html and in there you can see the the qr-code tag still remains as it is.
ANSWER
Answered 2020-Nov-29 at 07:39I was able to solve the issue using pure JavaScript QRCode instead of vue-qrcode library.
The final view
QUESTION
I have recently integrated this RazorLight package for Razor page rendering. While using I came to notice that there is a Template key that has to be defined. What actually this template key is and what it does?
...ANSWER
Answered 2020-Sep-10 at 09:51What actually this template key is and what it does?
If i use a different template, then should i use the same key or different?
Each template should have a templateKey that is associated with it while we create a template from string, so that we can re-run the cached template with this key. And the templateKey should be unique.
QUESTION
I have a Razor Page (.cshtml) which is a PDF Template. Now i am required to retreive html as string from the page itself to Save it as a PDF file. In MVC, i could use IRazonEngine interface for the same. But in Blazor what can used to obtain this.
Additionally, if i can use Blazor component instead of a Razor Page, how can i get the string of HTML?
Please help!
This is the sample Razor Page I have
...ANSWER
Answered 2020-Sep-09 at 09:40I think this is not about blazor or mvc pages, but you can use RazorEngine.NetCore library to convert the cshtml and fill in the dynamic data using a model and retrieve the completed html.
Here is a guide on how to do it: https://khalidabuhakmeh.com/generate-outputs-with-razor-engine-in-dotnet-core
Github project: https://github.com/fouadmess/RazorEngine
Here is a simple code which I have used in the past:
QUESTION
I have a solution in which most of the projects are VB.net projects which all target the .NET Framework 4.8. All of those specific projects compile properly and are running in production.
I have added a C# project that targets .net standard 2.0. The primary reason for this particular project is to create a component that can process razor templates (given a model of course) in order to create output files using the RazorLight_wik8wz nuget package (I don't really care which package I use so long as I can render a razor template in memory because the output generated by the model/template pair may be persisted in different places in different cases).
In theory, and based on my understanding, I should be able to reference and use a .net standard 2.0 library project from my other .net framework 4.8 projects. However, I can't seem to get this to work (even though everything compiles and runs).
I've tried several different packages based on RazorLight--but I get similar results when I try to use them. I'm simply not sure if I'm encountering a bug or if I'm not doing something properly.
The C# project is named "JobOutputGenerator." I have added the nuget package called "RazorLight_wik8wz" and created an object called JobOutput that currently looks like this:
...ANSWER
Answered 2019-Jun-07 at 18:12So after more searches I came across the following problem and set of posts. Following this workaround seems to have solved my problem for now.
Apparently this has been a problem for quite some time (since 2017--thanks Microsoft!) without a permanent fix.
The problem was first reported here:
If you read through this string of messages, you eventually come to this workaround near the bottom, with others confirming this person's findings. Following this workaround causes the DLL files to all get built/copied to the Debug folder and now the referenced DLL is no longer "missing" and the exception I was receiving at runtime is gone.
I made this modification to my JobOutputGenerator .csproj file, except that I used ;net48 instead of ;net461 .
NOTE THE TAG:
QUESTION
I have this cshtml file located in this path
...ANSWER
Answered 2019-Mar-28 at 14:04Inject IHostingEnvironment
and use _env.ContentRootPath
:
QUESTION
TL;DR; Is there anyway to tell CompilationLibrary.ResolveReferencePaths where to look for the references?
I've tried modifying the current working directory and even tried modifying the current AppDomain base directory to no avail.
So my team is currently using RazorLight to handle message templating in a .Net Core 2.2 console application.
I have added RazorLight 2.0.0-beta1 to a .Net Standard 2.0 library and created an interface for it. However, we discovered there was a conflict with a different library we were using due to that library using a C DLL. To solve the conflict we opted to remove the other library using the C DLL as no one had been using it's functionality yet. However, now we are at a point where we need both.
Luckily, RazorLight allows you to specify an assembly to use as the root. So I created a basic empty library project (RazorScope), that has no libraries other than RazorLight and our Models library.
RazorScope has the PreserveCompilationContext flag to true in it's csproj.
I have a pre-build event on our console app to publish RazorScope to the solution root/RazorScope folder and then a post-build and post-publish event that copies the RazorScope publish into the console app build/publish. I chose to go this route due to the "refs" folder that PreserveCompilationContext creates and I wanted to keep things clean. If I just add RazorScope as a project reference to the console application, it doesn't pull in those refs or the json.deps file for RazorScope...
The issue is that when RazorLight eventually calls CompilationLibrary.ResolveReferencePaths, it fails b/c it refuses to look in the RazorScope folder in the bin/publish directory and expects everything to be directly in the base directory. If I move the refs and other files up to base, it works fine, but now I've dirtied my console task bin/publish directory.
Is there anyway to tell CompilationLibrary.ResolveReferencePaths where to look for the references?
...ANSWER
Answered 2019-Mar-14 at 14:34The answer to this is just to not use the RazorLightEngine Nuget package. It's not really being maintained regularly anyway.
I ended up just rolling my own Roslyn compilation instance after using the .net core razor library to generate the c# code.
QUESTION
I'm trying to render a Razor view to a string from a Hosted Service. By using the IRazorViewEngine
I am able to render a view to a string using something like the following:
ANSWER
Answered 2018-Dec-04 at 03:39Try this:
QUESTION
I have being tasked with setting up a way where an admin user can easily pick articles to send out to a list of subscribers. The below image is what i'm trying to create but my problem is how get the view sent in an email. I have it created as a static template and as a razor template. I tried to use RazorEngine and Razorlight but can't figure them out.
Alot of the questions i have seen on this only adds one item to a email. e.g here and here. I am using MailKit to send emails but for the life of me i cant figure how to get an email body like above. My code looks like this
...ANSWER
Answered 2018-Aug-23 at 16:25After a long time searching i cam across this answer which enabled my to get the answer i was looking for. First i add this code to my constructor
QUESTION
I ran into this error with .NET Core 2.0 and .NET Core 2.1, while using RazorLight coupled with cshtml Razor template files for FluentEmail, in an ASP.NET Core app:
"Cannot find compilation library location for package XYZ"
Where XYZ seemed to change depending on what version of .NET Core I had deployed.
The error did not present itself in my dev environment, but reared its head after deployment, when hitting any API endpoint that required FluentEmail to use the Razor template files to generate the email body.
...ANSWER
Answered 2018-Jul-10 at 15:50Publish-time compilation of Razor files is enabled by default. In my case, I did not need this feature, because my Razor templates were being compiled by FluentEmail at runtime. By adding false
to the app's csproj file, publish-time compilation was disabled, and the error resolved.
Example csproj entry:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install RazorLight
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page