时间:2021-07-01 10:21:17 帮助过:2人阅读
控制器代码:
Controllers中BookController.cs的Add方法代码如下
public ActionResult Add()
{
return View();
}
[HttpPost]
public ActionResult Add(Book model)
{
if (ModelState.IsValid)
{
db.Book.AddObject(model);
int res = db.SaveChanges();
ViewData["status"] = "成功:" + DateTime.Now.ToString();
}
else {
ViewData["status"] = "失败:" + DateTime.Now.ToString();
}
return View();
}
运行效果截图:
测试环境:VS2010+.Net4.0+MVC4+EF4
EF DataBase First生成model的验证
标签: