Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ASP.NET MVC中使用EntityFramework6.Npgsql从Postgres数据库获取数据?_C#_Asp.net_Asp.net Mvc_Entity Framework_Npgsql - Fatal编程技术网

C# 如何在ASP.NET MVC中使用EntityFramework6.Npgsql从Postgres数据库获取数据?

C# 如何在ASP.NET MVC中使用EntityFramework6.Npgsql从Postgres数据库获取数据?,c#,asp.net,asp.net-mvc,entity-framework,npgsql,C#,Asp.net,Asp.net Mvc,Entity Framework,Npgsql,我正在使用Npgsql和EntityFramework6在ASP.NET MVC中创建一个登录应用程序。Npgsql,我想实现一个通过标识号检索密码的功能,即用户单击“我忘记了我的密码”按钮,然后他必须键入标识号,程序检查它是否存在或正确,然后,将显示更改密码的用户信息 用户的模型类: public partial class user { public int id { get; set; } [Display(Name = "Id number")]

我正在使用Npgsql和EntityFramework6在ASP.NET MVC中创建一个登录应用程序。Npgsql,我想实现一个通过标识号检索密码的功能,即用户单击“我忘记了我的密码”按钮,然后他必须键入标识号,程序检查它是否存在或正确,然后,将显示更改密码的用户信息

用户的模型类:

public partial class user
{

    public int id { get; set; }
    [Display(Name = "Id number")]
    [Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary the id number")]
    public string idnumber { get; set; }

    [Display(Name = "Name")]
    [Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary the name")]
    public string fname { get; set; }

    [Display(Name = "Last name")]
    [Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary the last name)]
    public string lname { get; set; }

    [Display(Name = "Password")]
    [Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary a pass")]
    [DataType(DataType.Password)]
    [MinLength(6, ErrorMessage = "Min six letters")]
    public string pass { get; set; }

    [Display(Name = "Confirm pass")]
    [DataType(DataType.Password)]
    [Compare("pass", ErrorMessage = "The pass don't match")]
    public string check_pass { get; set; }

    [Display(Name = "Email")]
    [Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary an email")]
    [DataType(DataType.EmailAddress)]
    public string email { get; set; }
}
因此,在
[HttpGet]
中,识别号由程序获取,而
[HttpPost]
中的信息由识别号更改,或者应该这样做

[HttpGet]
    public ActionResult recoverPass()
    {
        return View();
    }

    [HttpPost]
    public ActionResult recoverPass(userPassRecover user)
    {    
        using(inventarioEntitiesDBA dc = new inventarioEntitiesDBA())
        {
            var u = dc.user.Where(a => a.cedula == user.cedula).FirstOrDefault();

            dc.user.Remove(u);
            dc.user.Add(user);
            dc.SaveChanges();

            return View();
        }
    }

我真的不知道如何才能做到这一点,如果有人有同样的问题,我们非常感谢您的建议:

    [HttpGet]
    public ActionResult recoverPass()
    {

        return View();
    }

    [HttpPost]
    public ActionResult recoverPass(userRecoverPass user)
    {
        using (inventarioEntitiesDBA dc = new inventarioEntitiesDBA())
        {
            var u = dc.user.Where(a => a.idnumber == user.idnumber)?.FirstOrDefault();

            if (u != null)
            {
                u.pass = user.newpass;
                dc.SaveChanges();
            }

            return RedirectToAction("login");
        }
    }
其中,ʻuserRecoverPass`对象是仅请求信息以执行密码更改的模型