首页 > 解决方案 > 单击电子邮件中的链接时显示特定记录

问题描述

如何在电子邮件中包含一个链接,单击该链接将仅显示一条记录的数据?

现在我在索引页面中有一个数据表,它在应用程序打开时显示所有记录。当对记录进行更改时,会发送一封电子邮件,其中包含已编辑记录的 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");
    }
}

标签: c#htmlmodel-view-controller

解决方案


您可以添加一个可选参数。如果他有一个值,那么你按它排序,否则你将按原样返回页面。

return RedirectToAction("Index?id=1212");

像这样的东西。


推荐阅读