toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 259 forks source link

Failed to compile generated Razor template. The name 'Render' does not exist in the current context #262

Closed gmarokov closed 4 years ago

gmarokov commented 5 years ago

Description Hi. I try to use view with layout but I get the following error: `Failed to compile generated Razor template:

To Reproduce Steps to reproduce the behavior:

  1. My RazorLight setup:
private static string TEMPLATES_PATH = $@"{Directory.GetCurrentDirectory()}/Templates/Email";
public static async Task<string> RunCompile(string templateName, object model)
{
      var engine = new RazorLightEngineBuilder()
          .UseFilesystemProject(TEMPLATES_PATH)
          .UseMemoryCachingProvider()
          .Build();
       string result = await engine.CompileRenderAsync(templateName, model);           
       return result;
 }
  1. The rest is like the Wiki page for Layout pages: I did step 1 the model creation and step 2 layout/children page. Haven't performed the last step as it seems deprecated.

Information:

The Wiki page probably needs update too, as when tried the code there, It was marked as obsolete.

jzabroski commented 4 years ago

@gmarokov Thanks, but without knowing the model or the template content, it is hard to debug why you ran into this issue. Can you please either attach a zip file with the repro or push a regression test to the repository as a PR.

gmarokov commented 4 years ago

@jzabroski I'm no longer able to reproduce it and unfortunately can't remember how it was fixed. Rethinking to switch to the MVC version anyway. Thank you, I will close it.

jzabroski commented 4 years ago

What MVC version are you referring to? Thanks

gmarokov commented 4 years ago

To inject the engine instead of creating it :) Regards

jzabroski commented 4 years ago

Cool. Happy if i helped. One thing is that I an deprecated RazorLight.Mvc in 2.0.0 and moved AddRazorLight into the main package.

On Sun, Dec 22, 2019, 2:04 PM Georgi Marokov notifications@github.com wrote:

To inject the engine instead of creating it :) Regards

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/toddams/RazorLight/issues/262?email_source=notifications&email_token=AADNH7LTFUDIX5XQ57FKXATQZ6237A5CNFSM4IBDF7FKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHPXWUQ#issuecomment-568294226, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADNH7KZ3Q2SVPGE6YONYKTQZ6237ANCNFSM4IBDF7FA .