How to map index using jquery to repair indexes when remove

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Posts: 9
Joined: Mon 15 Aug 2016 10:17

How to map index using jquery to repair indexes when remove

Post by ahmedsa » Sun 18 Sep 2016 01:39

when remove any course from table list html his position in center or first it make problem

in index in database


IF I have list of courses as following :




IF I remove flash by JQUERY remove button then click save button

it delete flash and Photoshop

because there are wrong in delete courses by using remove function in jquery

if i remove php it is working without any problem because it is last item


using map function when remove but how to do that

if there are any solution for that without using map no problem

i use model as following

Code: Select all

public class Cusomemp2


    public List<EmployeeCourse> empcourses { get; set; }  

i use for edit httppost

Code: Select all

var result = db.Employees

         .Where(p => p.Id == custom.Id)  

         .Include(c => c.EmployeeCourses)  


    if (custom.empcourses.Any())  


        foreach (var ec in result.EmployeeCourses.ToList())//to remove existing EmployeeCourses  






    result.EmployeeCourses = custom.empcourses;  

in model view my code as following by jquery

actually i need to modify code below using map function if there are any function do that never mind

Code: Select all

$(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>")  



        $("#tb").on("click", ".r", function () {  

          // remove function  



// retrieve data in edit view using ajax


            url: "/Employee/getcoursesbyempid",  


            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>")  





to see what i need found in this image

Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: How to map index using jquery to repair indexes when remove

Post by Shalex » Mon 19 Sep 2016 17:57

1. Is your project code generated by a predefined template of Entity Developer or written by you manually?

2. Please send us a small test project with the corresponding DDL/DML script for reproducing the issue in our environment. In case of >2MB attachment, we recommend either using some file exchange server (send us the corresponding link) or uploading a test project to our FTP server (the credentials will be provided by email request).

Post Reply