3

Hej Community,

I am fairly new asking questions at SO so pardon if I am unclear at some point and just drop me a note and I will clarify.

Stack

  • ASP.NET MVC5
  • Postal.net

The Situation

I have a class library to send emails from my web app using Postal.Net. The view files (*.cshtml) are stored in the main web app in (~\Content\email\*) in order to access them at run time at the current domain. It works like a charm.

Now I'd like to re-use the email library and email templates in another web app. I put the same view files in the exact same place of this new web app (~\Content\email\*).

The email library finds the view files and I also made the razor related statements, such as @model, work and I can send emails.

The Issue

I am using @Raw in the the HTML email template which causes an error during compilation with the message:

CS0103 The name 'Raw' does not exist in the current context

The statement is needed in order to take care of special characters of names and to insert a working button into the email.

I added the following lines to the web.config of the new project:

<configSections>
  <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
  </sectionGroup>
</configSections>

<appSettings>
  <add key="webpages:Enabled" value="false" />
  <add key="webpages:Version" value="3.0.0.0" />
</appSettings>

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Optimization" />
      <add namespace="System.Web.Routing" />     
      <add namespace="_MyWebAppName_" />
    </namespaces>
  </pages>
</system.web.webPages.razor>

I hope you have an idea - i am running out of ideas to try.

Thanks,

/mmr

mmr
  • 383
  • 3
  • 12
  • Possible duplicate post of: https://stackoverflow.com/questions/23603593/razorengine-cannot-use-html-raw – landsteven Jan 05 '18 at 15:38
  • Possible duplicate of [RazorEngine: cannot use Html.Raw](https://stackoverflow.com/questions/23603593/razorengine-cannot-use-html-raw) – landsteven Jan 05 '18 at 15:39
  • 1
    try to use @Html.Raw i hope it's work for you – Muhammad Asad Jan 05 '18 at 16:09
  • I suggest you compare the `` element in the `\Views\Web.config` (not root `Web.config`) files of both applications and add the missing namespaces to the new one. – NightOwl888 Jan 05 '18 at 21:12
  • 1
    Thank you for your quick responses! I went through your hints and did not get it to work but got somewhat smarter. Using `@Html.Raw()` does not throw an error during build but an error when the RazorEngine tries to compile the email template during runtime - so it still does not work. So down the line `Raw` is just unknown for the compiler throwing that error during build. I compared the `` in any `Web.config` and they are identical to the extend they can be. However, the error is thrown. Any other ideas are appreciated :) – mmr Jan 08 '18 at 12:50
  • As a follow up for people who stumble upon this question: It is worth to look into [FluentEmail on GitHub](https://github.com/lukencode/FluentEmail) for .NET and .NET Core. I used it in another project for emailing and it is an ease and works like a charm. – mmr Jul 09 '18 at 14:44
  • As a follow up and to close the question: I recommend looking into [FluentEmail on Github](https://github.com/lukencode/FluentEmail). It is maintained and simple to implement. – mmr Sep 20 '18 at 11:32

1 Answers1

1

The problem could not be solved and the implementation was realized using another library called FluentEmail on Github. It is maintained and much simpler to implemented.

mmr
  • 383
  • 3
  • 12