Reputation: 1795
I'm following the tutorial on Hangfire.io: http://docs.hangfire.io/en/latest/tutorials/send-email.html
However when I copy and pasted the provided ~/Views/Emails/NewComment.cshtml code:
@model Hangfire.Mailer.Models.NewCommentEmail
To: @Model.To
From: [email protected]
Subject: New comment posted
Hello,
There is a new comment from @Model.UserName:
@Model.Comment
<3
I ran into 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 type of Views: in Views/Email: "MVC 5 View Page (Razor), MVC 5 View Page Layout (Razor)...", the page shows all elements preceded with "@" as can't find in current context. The Project Soln name is "Hangfire.Mailer".
Upvotes: 5
Views: 2797
Reputation: 3724
@Ulf's answer seems correct, but you mentioned that also any code preceded with @ is not working also (if I understood correctly).
Do you have a web.config file in your Views folder? you need it to configure razor and other stuff. if its not there, create a new project and copy paste the generated Views/web.config file into your own folder.
Upvotes: 0
Reputation: 1631
C# is case sensitive so you should use Hangfire or HangFire.
Now you are using uppercase in the definition:
namespace HangFire.Mailer.Models
But lowercase in the reference:
@model Hangfire.Mailer.Models.NewCommentEmail
The page you linked to uses lowercase in the namespace:
namespace Hangfire.Mailer.Models
Upvotes: 7
Reputation: 8591
First, (of all, you need to) install the Postal NuGet package to be able 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/
Upvotes: 1