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
Asp.net 如何为一个数据库集使用多个模型_Asp.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

Asp.net 如何为一个数据库集使用多个模型

Asp.net 如何为一个数据库集使用多个模型,asp.net,asp.net-mvc,asp.net-mvc-4,Asp.net,Asp.net Mvc,Asp.net Mvc 4,NETMVC体验! 我是asp.NETMVC4新手,所以我遇到了一个不知道如何解决的简单问题 这是我的NotActivatedUsers模型: public class NotActivatedUser { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int id { get; set; } [Required] [DefaultValue(fals

NETMVC体验! 我是asp.NETMVC4新手,所以我遇到了一个不知道如何解决的简单问题

这是我的NotActivatedUsers模型:

public class NotActivatedUser
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int id { get; set; }
    [Required]
    [DefaultValue(false)]
    public bool isActive { get; set; }
    [Required, DataType(DataType.EmailAddress)]
    public string email { get; set; }
    [Required]
    public string activeCode { get; set; }
    public DateTime createDate { get; set; }
}
这是我的注册模型:

public class SignUpModel
{
    [Key]
    public int id { get; set; }
    [EmailAddress(ErrorMessage = "Invalid Email!")]
    public string email { get; set; }
}
在我的数据库中:

public class Context : DbContext
{
    public DbSet<NotActivatedUser> notActivatedUser { get; set; }
}

你到底想做什么?我想注册,但不是从NotActivatedUsers模型。由于模型中电子邮件的错误消息不同,如果id和电子邮件映射到NotActivatedUsers模型中的id和电子邮件,则您只需创建一个新的NotActivatedUsers实体并插入到dbset。
public class AccountController : Controller
{
    private Context db = new Context();

    [HttpPost]
    [AllowAnonymous]
    public ActionResult SignUp(SignUpModel signUpModel)
    {
        if (ModelState.IsValid)
        {
            db.notActivatedUser.Add(signUpModel);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(signUpModel);
    }

    [AllowAnonymous]
    public ActionResult SignUp()
    {
        return View();
    }
}