Reputation: 57
I have a problem about using of RazorEngine While Creating plugin in nopcommerce.
My source code in the OnActionExecuted is:
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var m = filterContext.Result as ViewResultBase;
string newTag = @"@using Nop.Plugin.Misc.Helper.Extensions; @using Nop.Web.Framework.ViewEngines.Razor;
<div class='inputs date-of-birth'/ <label>@T('Account.Fields.DateOfBirth'):</label></div>";
var res = "Hello World";
if (m != null)
{
var model = m.Model as RegisterModel;
var service = Engine.Razor;
service.AddTemplate("templateRegister", newTag);
service.Compile("templateRegister");
res = service.Run("templateRegister", null, model);
filterContext.HttpContext.Response.Write(res);
}
}
But while compile and run, i was encounter with this error:
RazorEngine.Templating.TemplateCompilationException: '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: (36, 79) Too many characters in character literal Temporary files of the compilation can be found in (please delete the folder): C:\Users\Chegini.h\AppData\Local\Temp\RazorEngine_tfr2i1nu.3fl The template we tried to compile is: ------------- START ----------- @using Nop.Plugin.Misc.NchShamsiDate.Extensions; @using Nop.Web.Framework.ViewEngines.Razor;
@T('Account.Fields.DateOfBirth'):
Please advice me,if possible!
Upvotes: 1
Views: 2468
Reputation: 2414
The problem is with @T('Account.Fields.DateOfBirth')
, it needs double quotes @T("Account.Fields.DateOfBirth")
Upvotes: 2