Insert data using Entity Framework model

后端 未结 4 898
感情败类
感情败类 2020-11-27 03:07

I\'m trying to insert some data in my database using Entity Framework model, but for some unknown reasons to me, it does nothing.

Am I missing something here?

<
4条回答
  •  感动是毒
    2020-11-27 03:47

    [HttpPost] // it use when you write logic on button click event

    public ActionResult DemoInsert(EmployeeModel emp)
    {
        Employee emptbl = new Employee();    // make object of table
        emptbl.EmpName = emp.EmpName;
        emptbl.EmpAddress = emp.EmpAddress;  // add if any field you want insert
        dbc.Employees.Add(emptbl);           // pass the table object 
        dbc.SaveChanges();
    
        return View();
    }
    

提交回复
热议问题