0

I am receiving this error message when trying to go to the "CreatePreparer" view.

I've tried converting the Ints to Int32 in the model, as well as converting the Ints in the reader to string. I inserted a break point just before the controller return, and it appears that a 0 is returned.

Error Message: The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'CARE.Models.EmployeeModel'.

EmployeeModel

    namespace CARE.Models
    {
    public class EmployeeModel
    {
    public int UserID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public string Level { get; set; }
   }
   }

Controller

     public ActionResult CreatePreparer(EmployeeModel employeeModel)
    {

        return View("EmployeeDetails", employeeModel.UserID);
    }
   

Data Code

     public int Create (EmployeeModel employeeModel)
    {
        
        //access the database
        using (OdbcConnection connection = new OdbcConnection(connectionString))
        {
            string sqlQuery = "INSERT INTO dbo.Employee Values(@FirstName, @LastName, @Email)";

            OdbcCommand command = new OdbcCommand(sqlQuery, connection);
            command.Parameters.Add("@FirstName", System.Data.Odbc.OdbcType.VarChar, 100).Value = employeeModel.FirstName;
            command.Parameters.Add("@LastName", System.Data.Odbc.OdbcType.VarChar, 100).Value = employeeModel.LastName;
            command.Parameters.Add("@Email", System.Data.Odbc.OdbcType.VarChar, 100).Value = employeeModel.Email;
            command.Parameters.Add("@Level", System.Data.Odbc.OdbcType.VarChar, 100).Value = employeeModel.Level;
            
            connection.Open();
            int newID = command.ExecuteNonQuery();

            return newID;
        }
Jake
  • 13
  • 6

0 Answers0