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
- public class Cusomemp2
- {
- public int Id { get; set; }
- public List
empcourses { get; set; } - }
and when i need to retrieve courses for employee in edit view i use this code below
- $.ajax({
- url: "/Employeedata/getcoursesbyempid",
- data:{x:$("#hid").val()},
- success: function (res) {
- $.each(res, function (i, e) {
- $("#tb").append("
")+ index + "].CourseId' value='" + e.Id + "'/> " + e.CourseName + " - index++;
- });
- }
- })
Code
function retrieve data in controllerC#
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);
}
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
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Oct 2, 2016, 8:16 AM EDT
ahmed salahRank #2,612 · 534 reputationPosted Oct 2, 2016, 8:25 AM EDT