I have the following entities:
- BIEntities db = new BIEntities();
- public class SALES
- {
- public int IDs {get; set;}
- public string product { get; set; }
- ICollection<COUNTRIES> COUNTRIES { get; set; }
- ICollection<PRICES> PRICES { get; set; }
- }
-
- public class COUNTRIES
- {
- public int IDc { get; set; }
- public string country { get; set; }
- public virtual SALES SALES { get; set; }
- }
-
- public class PRICES
- {
- public int IDp { get; set; }
- public string price { get; set; }
- public string strength { get; set; }
- public virtual SALES SALES { get; set; }
- }
And a ViewModel:
- public class myViewModel
- {
- public int ID { get; set; }
- public string product { get; set; }
- List<string> country { get; set; }
- List<string> price { get; set; }
- List<string> strength { get; set; }
- }
I am trying to update (edit) all entities from myViewModel:
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit(int id, FormCollection collection, myViewModel myModel)
- {
- SALES sUpdate = db.SALES.FirstOrDefault(s => s.IDs == myModel.ID);
- if (sUpdate != null)
- {
- db.Entry(sUpdate).CurrentValues.SetValues(myModel);
- db.SaveChanges();
- }
- return RedirectToAction("Index");
- }
I am getting this exception:
"System.InvalidOperationException: The view 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.' or its master was not found or no view engine supports the searched locations."
Is this method correct? what other methods can I use to update the tables?