ahmed salah

ahmed salah

  • NA
  • 530
  • 141.7k

how to remove courses store in ids in edit post controller

Oct 7 2016 10:50 AM

In edit http post i need to remove courses stored in ids variable

note i need remove courses selected not edit
in jquery i store values of removed courses in ids variable
suppose i removed photoshop and flash it will store value of 3,4 in ids variable
below code when click remove it save values of courses removed in variable ids as array
 
  1. $("#tb").on("click"".r"function () {  
  2. $(this).parent().parent().hide();  
  3. $(this).parent().prev().prev().find("input").addClass("remove");  
  4. var ids = [];  
  5. var i = 0;  
  6. $(".remove").each(function () {  
  7. ids[i] = $(this).val();  
  8. i++;  
  9. });  
  10. for (var k = 0; k < ids.length; k++) {  
  11. alert(ids[k]);  
  12. }  
  13. });  
i show courses per employee from table EmployeeCourse in edit get as following
  1. var index = 0;  
  2. $.ajax({  
  3. url: "/Employeedata/getcoursesbyempid",  
  4. data:{x:$("#hid").val()},  
  5. success: function (res) {  
  6. $.each(res, function (i, e) {  
  7. $("#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>")  
  8. index++;  
  9. });  
  10. }  
  11. })  
  12. public JsonResult getcoursesbyempid(int x)  
  13. {  
  14. db.Configuration.ProxyCreationEnabled = false;  
  15. 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 });  
  16. return Json(data, JsonRequestBehavior.AllowGet);  
  17. }  
 my mode using as following
  1. public class Cusomemp2  
  2. {  
  3.     public int Id { getset; }  
  4.     public string Name { getset; }  
  5.     public List<EmployeeCourse> empcourses { getset; }  
  6. }  
 
when remove courses in edit HTTPPOST what i write here
  1. [HttpPost]  
  2. public ActionResult Edit(Cusomemp2 custom)  
  3. {  
  4. //what i write to remove courses saved in ids from table EmployeeCourse  
  5. return View();  
  6. }  
 
see image above for details

Answers (9)