Trying to do this edit page with asp.net MVC c# and getting the "NullReferenceException: Object reference not set to an instance of an object." error, but cannot see for the life of me what's actually wrong with the code, so a second pair of eyes would be hugely helpful :)
[HttpPost]
public ActionResult Edit(EquipmentIndexViewModel viewModel)
{
if (ModelState.IsValid)
{
var Equipment = TheEquipment.tblEquipments.Find(viewModel.EquipmentId);
Equipment.EquipmentID = viewModel.EquipmentId;
Equipment.EquipmentName = viewModel.EquipmentName;
Equipment.EquipmentICTVisible = viewModel.ICTVisibile;
Equipment.EquipmentPublicVisible = viewModel.PublicVisible;
TheEquipment.SaveChanges();
return RedirectToAction("EquipmentList");
}
return View(viewModel);
}
The stack trace is pointing to the following line:
Equipment.EquipmentID = viewModel.EquipmentId;
but it must be finding the ID find as Controller/Edit/ID is working fine, or seemingly anyway
any help would be appreciated!
Thanks