Ich verwende derzeit die RazorEngine-Bibliothek zum Erstellen von HTML-E-Mail-Vorlagen. Code: Hinzufügen von Namespaces bei Verwendung von RazorEngine
var result = Engine.Razor.RunCompile(File.ReadAllText(templateFilePath), key, typeof(T), data);
Innerhalb der Vorlage selbst ich den Zugriff auf einige der Hilfsmethoden von MVC zur Verfügung gestellt zu bekommen, nämlich @Html.Format(string string);
Jedoch Immer, wenn ich die Zusatzcodezeile in der Vorlage ist:
Errors while compiling a Template. Please try the following to solve the situation: * If the problem is about missing/invalid references or multiple defines either try to load the missing references manually (in the compiling appdomain!) or Specify your references manually by providing your own IReferenceResolver implementation. See https://antaris.github.io/RazorEngine/ReferenceResolver.html for details. Currently all references have to be available as files! * If you get 'class' does not contain a definition for 'member': try another modelType (for example 'null' to make the model dynamic). NOTE: You CANNOT use typeof(dynamic) to make the model dynamic! Or try to use static instead of anonymous/dynamic types. More details about the error: - error: (180, 97) The name 'Html' does not exist in the current context
Das erklärt, dass ich den richtigen Namespace verweisen muss. Frage ist, was referenziere ich und wo?
Haben Sie eine Lösung dafür gefunden? – Sidron