2 Replies - 485 Views - Last Post: 07 September 2016 - 09:43 AM

#1 ahmedba  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 141
  • Joined: 24-January 14

cannot convert from int to Models.employeecourse error

Posted 06 September 2016 - 04:15 PM

how to loop and delete record from database in table EmployeeCourse table
this is my code
when i try to delete record from removedCourseIds collection it give me error
cannot convert from int to Models.employeecourse

[HttpPost]  
ic ActionResult Edit(EditEmployeeVm model)  
     
    {  
        var existingCourseIds = db.EmployeeCourses.Where(g => g.EmployeeId == model.Id && g.CourseId!=null)  
                         .Select(f => f.CourseId.Value).ToList();  
        var removedCourseIds = existingCourseIds.Except(model.CourseIds);  
        //Now loop through these and delete it from db  
        foreach (var removedCourseId in removedCourseIds)  
        {  
//here error show in variable removedCourseId and show red line under this variable in line of remove
            db.EmployeeCourses.Remove(removedCourseId);  
        }  
  
  
        db.SaveChanges();  
  
  
        return View();  
    }  


Is This A Good Question/Topic? 0
  • +

Replies To: cannot convert from int to Models.employeecourse error

#2 andrewsw  Icon User is offline

  • say what now
  • member icon

Reputation: 6410
  • View blog
  • Posts: 25,910
  • Joined: 12-December 12

Re: cannot convert from int to Models.employeecourse error

Posted 07 September 2016 - 12:47 AM

It looks like you do not have a Remove() method that accepts an integer (CourseId).

You either need to create this method or pass the existing method an EmployeeCourse instance, rather than just an id/int.
Was This Post Helpful? 0
  • +
  • -

#3 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: cannot convert from int to Models.employeecourse error

Posted 07 September 2016 - 09:43 AM

What you need to check is the View that forwards to this action on that controller and see what parameters are being passed to which action in the controller. Please post the view that is posting to this controller.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1