3 Replies - 593 Views - Last Post: 14 October 2016 - 11:24 AM

#1 ahmedba  Icon User is offline

  • D.I.C Head

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

how to remove courses store in ids in edit post controller

Posted 08 October 2016 - 05:17 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


$("#tb").on("click", ".r", function () {  
$(this).parent().parent().hide();  
$(this).parent().prev().prev().find("input").addClass("remove");  
var ids = [];  
var i = 0;  
$(".remove").each(function () {  
ids[i] = $(this).val();  
i++;  
});  
for (var k = 0; k < ids.length; k++) {  
alert(ids[k]);  
}  
});  


i show courses per employee from table EmployeeCourse in edit get as following

var index = 0;  
$.ajax({  
url: "/Employeedata/getcoursesbyempid",  
data:{x:$("#hid").val()},  
success: function (res) {  
$.each(res, function (i, e) {  
$("#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>")  
index++;  
});  
}  
})  
public JsonResult getcoursesbyempid(int x)  
{  
db.Configuration.ProxyCreationEnabled = false;  
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 });  
return Json(data, JsonRequestbehavior.AllowGet);  
}  


my mode using as following

public class Cusomemp2  
{  
    public int Id { get; set; }  
    public string Name { get; set; }  
    public List<EmployeeCourse> empcourses { get; set; }  
}


when remove courses in edit HTTPPOST what i write here

[HttpPost]  
public ActionResult Edit(Cusomemp2 custom)  
{  
//what i write to remove courses saved in ids from table EmployeeCourse  
return View();  
}  


see image below for details

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: how to remove courses store in ids in edit post controller

#2 ahmedba  Icon User is offline

  • D.I.C Head

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

Re: how to remove courses store in ids in edit post controller

Posted 14 October 2016 - 06:50 AM

can any one help me in answer this question
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,356
  • Joined: 03-December 12

Re: how to remove courses store in ids in edit post controller

Posted 14 October 2016 - 07:09 AM

So you are trying to unset the empcourses in the code behind, not the javascript?
Was This Post Helpful? 0
  • +
  • -

#4 ahmedba  Icon User is offline

  • D.I.C Head

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

Re: how to remove courses store in ids in edit post controller

Posted 14 October 2016 - 11:24 AM

what actually i need to do how to pass ids variable from view to controller
then delete records saved in variable ids
what i need is server side not client side
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1