The type or name of the Hangfire namespace could not be found (did you specify a usage directive or assembly link?)

I follow the Hangfire.io manual: http://docs.hangfire.io/en/latest/tutorials/send-email.html

However, when I copy and paste the provided code ~ / Views / Emails / NewComment.cshtml:

@model Hangfire.Mailer.Models.NewCommentEmail To: @Model.To From: mailer@example.com Subject: New comment posted Hello, There is a new comment from @Model.UserName: @Model.Comment <3 

I encountered the following error:

 Error 2 The type or namespace name 'Hangfire' could not be found (are you missing a using directive or an assembly reference?) Error 3 The name 'Model' does not exist in the current context 

Models / NewCommentEmail.cs:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Postal; namespace HangFire.Mailer.Models { public class NewCommentEmail : Email { public string To { get; set; } public string UserName { get; set; } public string Comment { get; set; } } } 

It seems when I create almost any other kind of Views: in Views / Email: "MVC 5 (Razor), MVC 5 View Page Layout (Razor) ... View page," all elements preceded by "@" are displayed on the page, which cannot be found in the current context. The name of the Soln project is "Hangfire.Mailer".

+5
source share
3 answers

C # is case sensitive, so you should use Hangfire or HangFire.

Now you use uppercase letters in the definition:

 namespace HangFire.Mailer.Models 

But lowercase in link:

 @model Hangfire.Mailer.Models.NewCommentEmail 

The page associated with you uses lowercase in the namespace:

 namespace HangFire.Mailer.Models 
+7
source

First, you need to install the Postal NuGet package to use this class.

source: http://docs.hangfire.io/en/latest/tutorials/send-email.html#installing-postal

Installation package: https://www.nuget.org/packages/Postal.Mvc5/

+1
source

@Ulf's answer seems to be correct, but you mentioned that any code preceding @ does not work either (if I understood correctly).

Do you have a web.config file in your Views folder? you need to adjust the razor and other things. if not, create a new project and copy the generated Views / web.config file to your own folder.

0
source

Source: https://habr.com/ru/post/1211176/


All Articles