andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 168 forks source link

Non-ASP MVC, Using @HTML in Razor View #61

Open Lakshmipathijp opened 10 years ago

Lakshmipathijp commented 10 years ago

Hi,

I am using Postal component in Service Layer and using razor view(.cshtml) as mail template. In the template view, I am trying to use @HTML.Render() to render a partial view for message.

But getting bellow error Unable to compile template. The name 'Html' does not exist in the current context

Stack Info : at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Compilation\DirectCompilerServiceBase.cs:line 106 at RazorEngine.Templating.TemplateService.CreateTemplateType(String razorTemplate, Type modelType) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 256 at RazorEngine.Templating.TemplateService.GetTemplate[T](String razorTemplate, Object model, String cacheName) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 374 at RazorEngine.Templating.TemplateService.GetTemplate(String razorTemplate, Object model, String cacheName) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 352 at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 437 at RazorEngine.Razor.Parse(String razorTemplate, Object model, String cacheName) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Razor.cs:line 302 at Postal.FileSystemRazorView.Render(ViewContext viewContext, TextWriter writer) in c:\Users\Lakshmipathi.JP\Downloads\postal-master\src\Postal\FileSystemRazorView.cs:line 33 at Postal.EmailViewRenderer.RenderView(IView view, ViewDataDictionary viewData, ControllerContext controllerContext) in c:\Users\Lakshmipathi.JP\Downloads\postal-master\src\Postal\EmailViewRenderer.cs:line 95 at Postal.EmailViewRenderer.Render(Email email, String viewName) in c:\Users\Lakshmipathi.JP\Downloads\postal-master\src\Postal\EmailViewRenderer.cs:line 43 at Postal.EmailService.CreateMailMessage(Email email) in c:\Users\Lakshmipathi.JP\Downloads\postal-master\src\Postal\EmailService.cs:line 116 at Postal.EmailService.Send(Email email) in c:\Users\Lakshmipathi.JP\Downloads\postal-master\src\Postal\EmailService.cs:line 50 at CallSite.Target(Closure , CallSite , EmailService , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1) at ConsoleSample.Program.Main(String[] args) in c:\Users\Lakshmipathi.JP\Downloads\postal-master\src\Samples\ConsoleSample\Program.cs:line 29 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

Please help.

Thanks in advance.. Lp

mmunchandersen commented 9 years ago

I'm having a similar issue, when using postal with Hangfire (http://hangfire.readthedocs.org/en/latest/tutorials/send-email.html). The exception I get when using @Html.Partial("... is:

RazorEngine.Templating.TemplateCompilationException

Unable to compile template. Assuming assembly reference 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' matches 'System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35', you may need to supply runtime policy Other compilation errors may have occurred. Check the Errors property for more information.

RazorEngine.Templating.TemplateCompilationException: Unable to compile template. Assuming assembly reference 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' matches 'System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35', you may need to supply runtime policy

Other compilation errors may have occurred. Check the Errors property for more information. at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Compilation\DirectCompilerServiceBase.cs:line 106 at RazorEngine.Templating.TemplateService.CreateTemplateType(String razorTemplate, Type modelType) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 275 at RazorEngine.Templating.TemplateService.GetTemplate[T](String razorTemplate, Object model, String cacheName) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 393 at RazorEngine.Templating.TemplateService.GetTemplate(String razorTemplate, Object model, String cacheName) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 371 at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName) in c:_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 456 at Postal.FileSystemRazorView.Render(ViewContext viewContext, TextWriter writer) at Postal.EmailViewRenderer.RenderView(IView view, ViewDataDictionary viewData, ControllerContext controllerContext, ImageEmbedder imageEmbedder) at Postal.EmailViewRenderer.Render(Email email, String viewName) at Postal.EmailService.Send(Email email) at MyTestProject.Web.Controllers.AccountController.SendSurveyResponse(String userEmail, String lFromEmail, String lToFirstName, Int32 lResponseId, DateTime lResponseBegin, String lRespondent, String lStore, String lPathToFile) in c:\Projects\MyTestProject\MyTestProject.Web\Controllers\AccountController.cs:line 617

Please also see Hangfire thread: http://discuss.hangfire.io/t/error-using-razorengine-templating-templatecompilationexception/463

mattkoch614 commented 8 years ago

Having the same issue.