简体   繁体   中英

Kendo UI MVC Grid Not Updating

I am using a Kendo UI grid in MVC with Entity Framework, and I am new to both of these. I have been using many of the tutorials from Kendo, and for this I have used Ajax Editior. This is what I have for the update in my controller, but the update does not fire.

 public ActionResult Opt_Update([DataSourceRequest] DataSourceRequest request, PQAViewModel   
 optData)
    {
        if (ModelState.IsValid)
        {



            using (var pqaData = new PQAEntities())
            {
                var entity = new ProductQualityFileFull
                {
                    Jobber = optData.Jobber,
                    Dealer = optData.Dealer,
                    OptInd = optData.OptInd,
                    establish_date_time = optData.establish_date_time,
                    establish_id = optData.establish_id
                }; 
                pqaData.ProductQualityFileFulls.Attach(entity);
                pqaData.Entry(entity).State = EntityState.Modified; 
                pqaData.SaveChanges();
            }
        }

        return Json(new[] { optData.OptInd }.ToDataSourceResult(request, ModelState));

    }

The two lines that it indactes the problem is at are here: Any ideas on how to fix this?

 pqaData.ProductQualityFileFulls.Attach(entity);
 pqaData.Entry(entity).State = EntityState.Modified; 

If you are getting EntityValidationErrors then put in a specific exception handler for EF eg

try{
using (var pqaData = new PQAEntities())
        {
            var entity = new ProductQualityFileFull
            {
                Jobber = optData.Jobber,
                Dealer = optData.Dealer,
                OptInd = optData.OptInd,
                establish_date_time = optData.establish_date_time,
                establish_id = optData.establish_id
            }; 
            pqaData.ProductQualityFileFulls.Attach(entity);
            pqaData.Entry(entity).State = EntityState.Modified; 
            pqaData.SaveChanges();
        }
}
catch (DbEntityValidationException e)
 {
     //Check your errors here
}

It might be you're trying to put a null into a non-nullable field etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM