ahmed salah

ahmed salah

  • NA
  • 530
  • 148k

remove course from EmployeeCourse table when click save but

Sep 30 2016 7:21 AM

IF i have 3 courses for employee Michel

c# remove button

SQL remove button

asp.net remove button

save button

I need when click remove button for SQL course remove it by jquery from client side then when click save button remove it from EmployeeCourse table in database in sql server

i use this model

  1. public class Cusomemp2    
  2.    {    
  3.        public int Id { get; set; }    
  4.        public List<EmployeeCourse> empcourses { get; set; }    
  5.    
  6.    
  7.    }  
and when i need to retrieve courses for employee in edit view i use this code below
 
  1. $.ajax({  
  2.                 url: "/Employeedata/getcoursesbyempid",  
  3.                 data:{x:$("#hid").val()},  
  4.                 success: function (res) {  
  5.                     $.each(res, function (i, e) {  
  6.   
  7.   
  8.   
  9.                         $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + e.Id + "'/></td><td>" + e.CourseName + "</td><td><input type='button' value='remove' class='r'</td></tr>")  
  10.   
  11.   
  12.   
  13.                         index++;  
  14.                     });  
  15.                 }  
  16.   
  17.             })  
 function retrieve data in  controller
  1. public JsonResult getcoursesbyempid(int x)  
  2.        {  
  3.            db.Configuration.ProxyCreationEnabled = false;  
  4.            var data = db.EmployeeCourses.Where(a => a.EmployeeId == x).Join(db.Courses, a => a.CourseId, b => b.Id, (a, b) => new { Id = a.CourseId, CourseName = b.CourseName });  
  5.            return Json(data, JsonRequestBehavior.AllowGet);  
  6.        }  

so that i need after retrieve data in edit view do two task

remove course by jquery if iremoved sql

then remove the course from database in table EmployeeCourse

how i do that by code jquery and c# controller

EmployeeCourse table have three fields

Id,CourseId,EmployeeId

Course Table have

Id,CourseName

1 c#

2 sql

3 asp.net

Employee Table

have Id,Name


Answers (2)