c# - 单击电子邮件中的链接时显示特定记录
问题描述
如何在电子邮件中包含一个链接,单击该链接将仅显示一条记录的数据?
现在我在索引页面中有一个数据表,它在应用程序打开时显示所有记录。当对记录进行更改时,会发送一封电子邮件,其中包含已编辑记录的 ID 号。
我想我必须为此创建另一个视图?我在想我需要在接受 id 作为参数的控制器中实现 GET 操作,搜索底层数据存储并返回适当的记录。
另外,我发现这个 Open Specified ASP.NET MVC Views From Hyperlinks Inside Email Body 但我不太明白发生了什么,因为还涉及登录内容和其他内容。
我以前从未这样做过,我该怎么做?您能否提供一些示例代码?非常感谢。
这是我到目前为止有效的代码,但它缺少我要求的部分:
[HttpPost]
public ActionResult EditOneRecord(Ticket tix, string action, string confirm_value)
{
if (action == "Save")
{
using (DBModel db = new DBModel())
{
//Send email to user if IT edits the record
if (userName != tix.vcAssignedTo)
{
SmtpClient client = new SmtpClient();
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("nsantagata@fieldaero.com");
mailMessage.To.Add("nsantagata@fieldaero.com");
mailMessage.Subject = "Your Ticket Has Been Edited";
mailMessage.Body = "Your ticket " + tix.iNumber + " has been updated";
client.Send(mailMessage);
}
db.Entry(tix).State = EntityState.Modified;
tix.dtLastUpdated = System.DateTime.Now;
try
{
db.SaveChanges();
}
catch (Exception)
{
throw;
}
}
//Save to knowledgebase
if (confirm_value == "Yes")
{
HelpDeskDBHandle HDdb = new HelpDeskDBHandle();
if (HDdb.AddKnowledgeBase(tix))
{
}
}
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Index");
}
}
解决方案
您可以添加一个可选参数。如果他有一个值,那么你按它排序,否则你将按原样返回页面。
return RedirectToAction("Index?id=1212");
像这样的东西。
推荐阅读
- python - Vpython:属性“轴”必须是向量
- asp.net-core - 用于 SPA 的 ASP.NET Core 和 Identity Server 身份验证
- python - NameError:名称“配置”未定义
- c# - 如何从字符串创建多个语句 lambda 表达式
- java - 二元运算符的错误操作数类型 - 毕达哥拉斯三元组
- python - 使用 Matplotlib 进行类别轴的交互式绘图
- android - 使用 setAction 和 setData 时 putExtra 不传输数据
- dialogflow-es - 如何在对话流中获取登录用户的电子邮件 ID?
- c++ - 检查winapi函数是否可用
- c# - PHP json 验证