我将遵循Hangfire.io上的教程进行翻译:http://docs.hangfire.io/en/latest/tutorials/send-email.html
然而,当我复制并粘贴提供的~/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
我遇到了以下错误:
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; }
}
}
当我创建其他类型的视图时,例如在Views/Email中使用"MVC 5 View Page (Razor)"或"MVC 5 View Page Layout (Razor)",页面上所有以"@"开头的元素都显示为无法在当前上下文中找到。该项目解决方案名称为"Hangfire.Mailer"。
Hangfire.Mailer.Models.NewCommentEmail
类的定义吗? - jamesSampicacs
文件和cshtml
文件位于解决方案中的不同项目中,则需要在包含cshtml
文件的项目中添加引用。 - Omri AharonMyApplication.Models
的东西,其中MyApplication被替换为你的应用程序名称(例如JerryBlog
)。 - mason