@Raw statement is unknown in razor view file (ASP.NET MVC5)

985 Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

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.