开发者

The 'ModifiedOn' property on 'WareHouse' could not be set to a 'DateTime' value. You must set this property to a non-null value of type 'String'

This is my controller class.

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.Sa开发者_Python百科veChanges();
            return RedirectToAction("WareHouseIndex");
        }
    }
}

and this is my table design..

The 'ModifiedOn' property on 'WareHouse' could not be set to a 'DateTime' value. You must set this property to a non-null value of type 'String'

whenever i want to run "Admin/WareHouseIndex" action there is a problem occured is "The 'ModifiedOn' property on 'WareHouse' could not be set to a 'DateTime' value. You must set this property to a non-null value of type 'String'."

even i there is no null entry in modifiedOn field. Please check it and suggest me what mistake i have done.


There is likely a mismatch of types between your Database Type and your POCO Type for that property. If I had to guess I'd say your property type is a String or a non-nullable DateTime and it should be a nullable DateTime, ie:

public DateTime? ModifiedOn { get; set; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜