Problemwhen remove any course from table list html his position in center or first it make problemin index in databaseDetailsIF I have list of courses as following :DelphiFlashPhotoshopIF I remove flash by JQUERY remove button then click save buttonit delete flash and Photoshopbecause there are wrong in delete courses by using remove function in jqueryif i remove php it is working without any problem because it is last itemsuggestionusing map function when remove but how to do thatif there are any solution for that without using map no problemi use model as followingpublic class Cusomemp2 { public List<EmployeeCourse> empcourses { get; set; } } } i use for edit httppostvar result = db.Employees .Where(p => p.Id == custom.Id) .Include(c => c.EmployeeCourses) .FirstOrDefault(); if (custom.empcourses.Any()) { foreach (var ec in result.EmployeeCourses.ToList())//to remove existing EmployeeCourses { db.EmployeeCourses.Remove(ec); db.SaveChanges(); } } result.EmployeeCourses = custom.empcourses; db.SaveChanges(); in model view my code as following by jqueryactually i need to modify code below using map function if there are any function do that never mind$(function () { //add courses using drop down var index = 0; $("#CourseId").change(function () { var id = $(this).val(); var txt = $("#CourseId option:selected").text(); $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + id + "'/></td><td>" + txt + "</td><td><input type='button' value='remove' class='r'</td></tr>") index++; }); $("#tb").on("click", ".r", function () { // remove function $(this).parent().parent().remove(); $(this).parent().prev().prev().remove(); }); // retrieve data in edit view using ajax $.ajax({ url: "/Employee/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++; }); } }) }); see image below to understand what i need
Problemwhen remove any course from table list html his position in center or first it make problemin index in databaseDetailsIF I have list of courses as following :DelphiFlashPhotoshopIF I remove flash by JQUERY remove button then click save buttonit delete flash and Photoshopbecause there are wrong in delete courses by using remove function in jqueryif i remove php it is working without any problem because it is last itemsuggestionusing map function when remove but how to do thatif there are any solution for that without using map no problemi use model as following
public class Cusomemp2 { public List<EmployeeCourse> empcourses { get; set; } } } i use for edit httppost
var result = db.Employees .Where(p => p.Id == custom.Id) .Include(c => c.EmployeeCourses) .FirstOrDefault(); if (custom.empcourses.Any()) { foreach (var ec in result.EmployeeCourses.ToList())//to remove existing EmployeeCourses { db.EmployeeCourses.Remove(ec); db.SaveChanges(); } } result.EmployeeCourses = custom.empcourses; db.SaveChanges();
in model view my code as following by jqueryactually i need to modify code below using map function if there are any function do that never mind
$(function () { //add courses using drop down var index = 0; $("#CourseId").change(function () { var id = $(this).val(); var txt = $("#CourseId option:selected").text(); $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + id + "'/></td><td>" + txt + "</td><td><input type='button' value='remove' class='r'</td></tr>") index++; }); $("#tb").on("click", ".r", function () { // remove function $(this).parent().parent().remove(); $(this).parent().prev().prev().remove(); }); // retrieve data in edit view using ajax $.ajax({ url: "/Employee/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++; }); } }) }); see image below to understand what i need