我添加了一个属性"密码"在我的班级模型用户。它现在显示在Register.cshtml
{。}}。
<form action="~/Users/SaveRegister" method="post">
@Html.ValidationSummary(true)
@Html.AntiForgeryToken()
<div class="editor-label">
@Html.LabelFor(model => model.user_name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.user_name)
@Html.ValidationMessageFor(model => model.user_name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.password)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.password)
@Html.ValidationMessageFor(model => model.password)
</div>
<p>
<input type="submit" value="Register" />
</p>
</form>
但是当我按db.Users.Add(User);
时,它会在我的控制器Register
中提供例外。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SaveRegister(Airlineapp.Models.User User, HttpPostedFileBase file)
{
db.Users.Add(User);
db.SaveChanges();
return RedirectToAction("Index");
}
答案 0 :(得分:-1)
有人连接到数据库。尝试切换到另一个数据库,然后删除它:
尝试
SP_WHO
看看谁联系了
和KILL
或使用using (context db = new context())