Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.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
Asp.net mvc MVC成员。UpdateUser(u);不支持指定的方法_Asp.net Mvc - Fatal编程技术网

Asp.net mvc MVC成员。UpdateUser(u);不支持指定的方法

Asp.net mvc MVC成员。UpdateUser(u);不支持指定的方法,asp.net-mvc,Asp.net Mvc,我试图让用户更改他的电子邮件,但当我尝试更新数据库时,我得到一个异常:不支持指定的方法 [HttpPost] [ValidateAntiForgeryToken] public ActionResult ManageEmail(LocalEmailModel model) { //UserProfile u = new UserProfile(); if (ModelState.IsValid) { bool TryPasswordNow;

我试图让用户更改他的电子邮件,但当我尝试更新数据库时,我得到一个异常:不支持指定的方法

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ManageEmail(LocalEmailModel model)
{
    //UserProfile u = new UserProfile();

    if (ModelState.IsValid)
    {
        bool TryPasswordNow;
        var user = Membership.GetUser(User.Identity.Name);

        MembershipUser u = Membership.GetUser(User.Identity.Name);

        try
        {
            TryPasswordNow = WebSecurity.ChangePassword(User.Identity.Name,   model.OldPassword, model.OldPassword);
        }

        catch (Exception)
        {
            TryPasswordNow = false;
        }

        if (TryPasswordNow == true)
        {
            user.Email = model.NewEmail;
            db.SaveChanges();

            u.Email = model.NewEmail;
            Membership.UpdateUser(u);
        }

        return RedirectToAction("Manage", "Account");
    }
    return RedirectToAction("Manage", "Account");
}

如您所见,我尝试了db.savechanges和membership.updateuser。第一封邮件通过了,但没有更改电子邮件,第二封邮件给了我一个例外。这两个不都应该起作用吗?为什么我的零钱没有登记?谢谢..

如果您使用的是SimpleMembership提供程序(请检查您的web.config),这个问题可能是一个问题


再进一步说明一下,之所以调用SaveChanges()是因为Entity框架没有跟踪MembershipUser对象,所以调用它对数据库没有影响。

您好,谢谢您的回复。好的,我明白了,但是应该不是db.SaveChanges();保存我的更改?不是在这种情况下-MembershipUser(您希望通过“user”变量保存的对象)不是实体框架跟踪的实体-它只是一个与任何其他对象一样的对象,就SaveChanges()而言,没有任何更改。