我正在尝试构建自己的邮件控制器来处理自定义电子邮件生成。
我有一个默认的布局邮件程序,可以处理邮件模板的所有常用部分。
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>@ViewBag.Title</title>
</head>
<body>
<header style="width: 100%; height: auto; padding: 20px 20px 10px 20px; border-collapse: collapse; border-spacing: 0; background-color: #eee; color: #555 !important; ">
<h1 style="margin-top: -10px; margin-bottom: 0;height:80px; ">
<img style="float:left;" src="https://mylogoimage" alt="logo" />
<span style="padding: 30px 0 0 10px; float: left; color: #555 !important; font-size: 28px;"> Confirm Registration</span>
<a style="padding: 35px 40px 0 0; float: right; color: #555 !important; font-size: 14px;" href="#">View in Browser</a>
</h1>
</header>
<div id="emailbodytext">
@RenderBody()
</div>
<footer style="background-color: #eee; color: #555 !important; height:50px;padding-top:10px;">
<p style="margin-left:25px;">
<strong><span style="font-size:1em;font-style:italic;">You are receiving this email because you registered an account at TraderToolkit.com</span></strong>
<img style="float:right;margin-right:25px;padding-bottom:10px;" src="https://mylogoimage" alt="logo" /><br />
</p>
</footer>
</body>
</html>
我创建了一个使用上面显示的布局的注册视图。哪个VS生成为;
@{
Layout = "~/Views/Mailers/_LayoutMailer.cshtml";
}
然后我将我的模型添加到参考
@model EmailViewModels.RegistrationConfirmOutputViewModel
VS2015很好。然后我为视图添加了html。
<section style="font-size:1.1em;">
<h3 style="margin-left: 10px;">Greetings @model.FullName,</h3>
<p style="margin-left: 25px;">
You (or someone else) entered this email address to register an account at @model.ApplicationName.<br /><br/>
The request was sent from this IPAddress -- <span style="font-size:1.15em;font-weight:bold;">@model.IpAddress</span>.
<br />
The approximate geographic location from where this request was sent is <span style="font-size:1.15em;font-weight:bold;">@model.IpLocation</span>.
<br /><br />
If you sent the request and wish to confirm your registration please click the button below to complete your registration
<br />
@Html.ActionLink("Confirm Registration", "ConfirmRegistration", "Account", new { parameters = @model.UserId }, null)
<br /><br />
If you feel your email account has been compromised please take the appropriate steps to secure your account.<br />
Please click the button below so we can remove this registration request.<br />
@Html.ActionLink("Delete Request", "ChangePassword","Account",new { parameters = @model.UserId },null)
<br /><br />
Thank you.<br />
The staff at @model.ApplicationName
</p>
这就是崩溃的地方。声明中的布局现在为红色,每次引用@model
时都是如此。错误现在说:
无法解析符号布局
当前上下文中不存在@model
个属性。
是否存在使用无法使用模型引用的布局的视图?我是学习MVC的新手,不知道如何继续学习。
此外,我正确使用Html.ActionLink
因为@Html
也是红色的。
更新 我尝试通过在视图创建对话框中引用视图模型来重新创建视图(也引用应用程序ocntext),这样就不会创建视图,说明实体中没有定义任何键(RegistrationConfirmationOutputViewModel)。为什么viewmodel需要密钥?该视图是否仅创建对话框参考域模型?