我在我的班级模型用户中添加了一个属性“密码”。它现在在我看来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");
}
有人连接到数据库。尝试切换到另一个数据库,然后,删除它:
尝试
SP_WHO
看谁有联系
和KILL
如果需要或使用using (context db = new context())