how to delete assigned courses only not all courses for employee
<p><strong>Problem</strong></p>

<p>In edit view when i click remove course then click save it remove all course not </p>

<p>only i selected for remove</p>

<p><strong>Details</strong></p>

<p>if i have courses a,b,c for employee name michel then remove course a</p>

<p>and click save it delete all courses b,c also deleted</p>

<p>I need actually delete assigned for remove only meaning remove a and remaining </p>

<p>b,c. see image below it show what i need clearly</p>

<p>model Cusomemp2</p>

<pre><code> public class Cusomemp2
    {
        public int Id { get; set; }//employee
        public string Name { get; set; }//employee
        public List&lt;EmployeeCourse&gt; empcourses { get; set; }//employeecourse

    }
</code></pre>

<p>in edit http post i need when click save button remove only assigned for delete</p>

<pre><code>[HttpPost]
        public ActionResult Edit(Cusomemp2 custom)
        {

            var result = db.Employees
                 .Where(p =&gt; p.Id == custom.Id)
                 .Include(c =&gt; c.EmployeeCourses)
                 .FirstOrDefault();

            if (custom.empcourses.Any())
        {
//in this foreach remove courses(not success)
            foreach (var ec in result.EmployeeCourses.ToList())//to remove existing EmployeeCourses
            {
                db.EmployeeCourses.Remove(ec);
                db.SaveChanges();

            }
        }

            return View();
        }
</code></pre>

<p>when click remove course it give value 0 for hidden course</p>

<p>the following show list of courses in view model</p>

<pre><code>            var index = 0;
            $("#CourseId").change(function () {

                var id = $(this).val();
                var txt = $("#CourseId option:selected").text();
                $("#tb").append("&lt;tr&gt;&lt;td&gt;&lt;input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + id + "'/&gt;&lt;/td&gt;&lt;td&gt;" + txt + "&lt;/td&gt;&lt;td&gt;&lt;input type='button' value='remove' class='r'&lt;/td&gt;&lt;/tr&gt;")

                index++;
            });
            $("#tb").on("click", ".r", function () {
                $(this).parent().parent().hide();
                $(this).parent().prev().prev().find("input").val("0");
            });
</code></pre>