db.Data1 = del.thistable;???
del.thistable= db.Data1.ToList();
public class HomeController : Controller { private testContext db = new testContext(); private DeleteModel del = new DeleteModel(); public ActionResult Delete(int testID) { del.thistable= db.Data1.ToList(); del.thistable.Remove(del.thistable.SingleOrDefault(o => o.testID == testID)); db.Data1 = del.thistable;??? } }
public class Table1 { [Key] public int testID { get; set; } public string datetime { get; set; } public string col1 { get; set; } public string col2 { get; set; } public string col3 { get; set; } } public class DeleteModel { public string errorcode { get; set; } public List<Table1> thistable { get; set; } } public class testContext : DbContext { public DbSet<Table1> Data1 { get; set; } }
Try replacing your Delete method with the following and you should be good to go.
Delete
public ActionResult Delete(int testId) { var table1 = new Table1() { testID = testId }; db.Entry(table1).State=EntityState.Deleted; db.SaveChanges();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)