I have a viewmodel that contains a List, such as this:
class School
{
public List<Student> Students { get; set; }
}
class Student
{
public int Id { get; set; }
public String Name { get; set; }
}
I have a form on which I am submitting multiple students info related to single school. Now I can add/remove a single student from the form.
Adding works fine, but my issue and my question is related to deletion of a student.
So let me explain this with an example:
Lets say I add 3 students then there names and Ids will be binded to the model in this way:
Students[0].Id = "1"
Students[0].Name = "Student A"
Students[1].Id = "2"
Students[1].Name = "Student B"
Students[2].Id = "3"
Students[2].Name = "Student C"
If I save this it works just fine. But lets say I delete the student with Id ="2".On submitting what is happening is that only the student with id = "1" is getting binded and rest after deleted index(that is student with id="3") is not getting binded.
My question is that : Is it at all possible to bind that id="3" after deletion of id="2" ? Or In proper terms is it possible to bind/submit a list with skipped indices.
I found below mentioned articles on stackoverflow itself but what I can infer from them is bit contradicting or maybe I am not understanding them properly.
I am not good with explaining problems. So please tell me if I can add anything to make it more descriptive.
Thank you.
Example Delete Code:
Fiddle for delete Js code