使用密码和电子邮件保存数据并向用户发送电子邮件

时间:2016-10-06 00:13:20

标签: asp.net asp.net-mvc asp.net-mvc-5

我正在开发一个Asp.Net MVC 5项目。我有这个控制器来保存用户的数据。现在我想在我保存数据后通过我们自动生成的密码向他/她发送电子邮件。 这是我的创建动作

[HttpPost]
    public ActionResult Create(TeacherViewModel viewModel)
    {
        if (!ModelState.IsValid)
        {
            return View("Create", viewModel);
        }

        var teacher = new Teacher
        {
            Identifier = viewModel.Identifier,
            Name = viewModel.Name,
            Surname = viewModel.Surname,
            Email = viewModel.Email,
            PhoneNumber = viewModel.PhoneNumber,
            Ville = viewModel.Ville,
            Block = viewModel.Block,
            Password = viewModel.Password
        };

        _context.Teachers.Add(teacher);
        _context.SaveChanges();

        return RedireToAction("Index","Home");

1 个答案:

答案 0 :(得分:0)

使用密码和电子邮件保存数据并向用户发送电子邮件

由于您需要在保存数据后通过电子邮件发送电子邮件和密码,请根据您的要求参考下面提到的代码,希望它对您有所帮助。

string searchKey="D";
int reqPosition=list_Position.IndexOf(searchKey);
if(reqPosition!=-1)
{
    Console.WriteLine("Corresponding Id is {0}",list_ID[reqPosition]);
}
else
   Console.WriteLine("Not Found");
相关问题