Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.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# 首先使用代码使用MVC5实体框架更改密码_C#_Asp.net_Linq_Asp.net Mvc 5_Ef Code First - Fatal编程技术网

C# 首先使用代码使用MVC5实体框架更改密码

C# 首先使用代码使用MVC5实体框架更改密码,c#,asp.net,linq,asp.net-mvc-5,ef-code-first,C#,Asp.net,Linq,Asp.net Mvc 5,Ef Code First,我正在尝试使用下面的控制器方法更新密码 public ActionResult ChangePassword([Bind(Include = "NewPassword")] Register ChangePassword, FormCollection frm) { string Email = Session["email"].ToString(); var existingEmail = db.Registers.FirstOrDefault(

我正在尝试使用下面的控制器方法更新密码

  public ActionResult ChangePassword([Bind(Include = "NewPassword")] Register ChangePassword, FormCollection frm)
    {

        string Email = Session["email"].ToString();

        var existingEmail = db.Registers.FirstOrDefault(c => c.EmailId == Email);


        if (existingEmail != null)
        {
            //Need to update password

        }

        return View();


    }
下面是注册模型

   [Table("Register")]
public class Register
{
    [Key]
    public int Sno { get; set; }

    [Required(ErrorMessage = "Name is required.")]
    [Display(Name = "Full name")]
    public string Fullname { get; set; }
    [Display(Name = "Email Id")]
    [Required(ErrorMessage = "Email is required.")]
    public string EmailId { get; set; }
    [Required(ErrorMessage = "Password is required.")]
    public string Password { get; set; }

    [Required(ErrorMessage = "Mobile is required.")]
    public string Mobile { get; set; }
    [Required(ErrorMessage = "Address is required.")]
    public string Address { get; set; }
    public string State { get; set; }
    public string City { get; set; }
    [Required(ErrorMessage = "Entity is required.")]
    public string EntityType { get; set; }
    public string Website { get; set; }

    public string PinCode { get; set; }


      public string accountactivated { get; set; }

     public int RoleId { get; set; }

     [Display(Name = "New Password")]
      [NotMapped]
      public string NewPassword { get; set; }
     [Display(Name = "Confirm New Password")]
     [NotMapped] // Does not effect with your database
     [System.Web.Mvc.Compare("NewPassword", ErrorMessage = "Password not match")]
     public string ConfirmNewPassword { get; set; }


   }
下面是我更改密码的设计

    @using (Html.BeginForm())
  {
  @Html.AntiForgeryToken()

 <div class="form-horizontal">

    <hr />
    @Html.ValidationSummary(true)

    <div class="form-group">
        @Html.LabelFor(model => model.NewPassword, new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.TextBoxFor(model => model.NewPassword, new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.NewPassword)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ConfirmNewPassword, new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.PasswordFor(model => model.ConfirmNewPassword, new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.ConfirmNewPassword)
        </div>
    </div>



    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Change Password" class="btn btn-default" />
        </div>
    </div>
    </div>
    }
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()

@Html.ValidationSummary(true) @LabelFor(model=>model.NewPassword,new{@class=“controllabel col-md-2”}) @Html.TextBoxFor(model=>model.NewPassword,new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.NewPassword) @LabelFor(model=>model.ConfirmNewPassword,new{@class=“control label col-md-2”}) @Html.PasswordFor(model=>model.ConfirmNewPassword,new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.ConfirmNewPassword) }

请帮助解决这个问题,并等待您的回复。我对使用asp.NETMVC代码开发我的项目非常陌生,这是我正在做的第一个项目。我提前表示感谢。

您看到了什么?我无法为单个字段编写linq更新查询来更新密码@D219启动一个新项目,单击“更改身份验证”按钮并选择单个用户帐户。如果您是新手,则应先阅读教程: