这是我的控制器类。
namespace CalcoWOMS.Controllers
{
public class AdminController : Controller
{
private WOMSEntities db = new WOMSEntities();
public ViewResult WareHouseIndex()
{
return View(db.WareHouse.ToList());
}
public ViewResult WareHouseDetails(int id)
{
WareHouse wareHouse = db.WareHouse.Single(m => m.ID == id);
return View(wareHouse);
}
public ActionResult WareHouseCreate()
{
return View();
}
[HttpPost]
public ActionResult Create(WareHouse wareHouse)
{
if (ModelState.IsValid)
{
db.WareHouse.AddObject(wareHouse);
db.SaveChanges();
return RedirectToAction("WareHouseIndex");
}
return View(wareHouse);
}
//
// GET: /Admin/Edit/5
public ActionResult WareHouseEdit(int id)
{
WareHouse wareHouse = db.WareHouse.Single(m => m.ID == id);
return View(wareHouse);
}
[HttpPost]
public ActionResult WareHouseEdit(WareHouse wareHouse)
{
if (ModelState.IsValid)
{
db.WareHouse.Attach(wareHouse);
db.ObjectStateManager.ChangeObjectState(wareHouse, EntityState.Modified);
db.SaveChanges();
return RedirectToAction("WareHouseIndex");
}
return View(wareHouse);
}
//
// GET: /Admin/Delete/5
public ActionResult WareHouseDelete(int id)
{
WareHouse wareHouse = db.WareHouse.Single(m => m.ID == id);
return View(wareHouse);
}
[HttpPost, ActionName("WareHouseDelete")]
public ActionResult WareHouseDeleteConfirmed(int id)
{
WareHouse wareHouse = db.WareHouse.Single(m => m.ID == id);
db.WareHouse.DeleteObject(wareHouse);
db.SaveChanges();
return RedirectToAction("WareHouseIndex");
}
}
}
这是我的桌子设计..
每当我想运行“Admin / WareHouseIndex”动作时,就会出现问题 “'WareHouse'上的'ModifiedOn'属性无法设置为'DateTime'值。您必须将此属性设置为'String'类型的非null值。”
即使我在modifiedOn字段中没有空条目。请检查一下,并告诉我我做了什么错误。
答案 0 :(得分:0)
您的Database Type
和POCO Type
之间可能存在不匹配的类型。如果我不得不猜测我会说你的属性类型是String
或不可为空的DateTime,它应该是可以为空的DateTime
,即:
public DateTime? ModifiedOn { get; set; }