INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

cannot save changes of courses if remove in edit httppost

cannot save changes of courses if remove in edit httppost

(OP)
Problem

when remove course then click submit not save changes although

it removed from client side by jquery

Details

in edit view for every employee i need to do changes by remove or add new courses for

employee

if i add new courses then click submit button it save what i do

but if i remove course from courses then click submit it will not save courses i

removed

so that i need to check what is wrong in my code

my code working without any problem but only have problem

i cannot save courses removed in database in employeecourse table when click submit

employeecourse table have Id,EmployeeId,CourseId

jquery remove client side attached with my question

code

my code as following

CODE --> c#

[HttpPost]  
        public ActionResult Edit(EditEmployeeVm model)  
        {  
            var emp = db.Employees.FirstOrDefault(f => f.Id == model.Id);  
            foreach (var couseid in model.CourseIds)  
            {  
                db.EmployeeCourses.Add(new EmployeeCourse { CourseId = couseid, EmployeeId = emp.Id });  
                db.SaveChanges();  
            }  
        
            return View();  
my(custom model) view model using for that  
 public class EditEmployeeVm  
    {  
        public int Id { set; get; }  
        public List<SelectListItem> Courses { get; set; }  
        public int[] CourseIds { set; get; }  
        public List<CourseVm> ExistingCourses { set; get; }  
    }  
    public class CourseVm  
    {  
        public int Id { set; get; }  
        public string Name { set; get; }  
    }  
} 

to show what i need clearly see image below

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close