Closed joshnoe closed 4 years ago
@joshnoe Hi, can you use the GitHub deep linking of code feature to link me to which example you're referring to? On the left hand side bar of the code you can say "reference in new issue" and it will create an issue with the deep link. You can then copy-paste that here, thank you for your help and will try to get back quickly.
I tried await engine.CompileRenderAsync(resourceName, model)
with
var xmlName = "MyTemplate.xml";
var assembly = Assembly.GetExecutingAssembly();
string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith(xmlName));
but I only receive false
Did you find the solution?
@zevero - I'm confused. What do you mean, you only receive false
? CompileRenderAsync returns a string, not a bool type. Nothing in your example returns a bool, either?
@jzabroski oh sorry I think I received null or i catched null - dont remeber exactly, but @joshnoe is right, that it is missing in docs. I worked around parsing the empedded ressource to string myself.
In version 3.0.2 one of the implementations of CompileRenderAsync
has been marked as obsolete.
My current implementation is as follows:
var razorLightEngine = new RazorLightEngineBuilder()
.UseEmbeddedResourcesProject(typeof(ReportBase))
.UseMemoryCachingProvider()
.Build();
var template = typeof(ReportBase).Assembly.GetEmbeddedResourceByKey(this.ReportTemplateKey);
var result = await razorLightEngine.CompileRenderAsync(Guid.NewGuid().ToString(), template, model);
But this implementation no longer works. If I implement this method, which is stated as the one to use:
Task<string> CompileRenderAsync<T>(string key, T model, ExpandoObject viewBag = null);
How would I specify my template (aka my html / view)
Thanks in advance!
Please add an example of how to properly format key
in await engine.CompileRenderAsync(...)
method when using EmbeddedResource as the source.
https://github.com/toddams/RazorLight#embeddedresource-source
@Programm3r Thanks for your example. I am a bit confused when you say "In version 3.0.2", since RazorLight is still on RazorLight-2.0.0-beta releases.
I pushed an example - but I have to say I was pretty confused by this request/discussion, so it's possible the example will need to be updated further as I understand what people want help with.
RazorLight support Embedded Resources, but the example is missing the call to
await engine.CompileRenderAsync
so it's unclear how to use this source.