In ASP.NET MVC we can simply bind and post a custom type of collection. Here I am demonstrating a sample application for implementing this.
Create a sample class of type Person
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Create a controller with two action such as Index for loading a List and Register for posting List
public class PersonController : Controller
{
public ActionResult Index()
{
var persons = new List()
{
new Person {FirstName = "Jameel", LastName = "VM"},
new Person {FirstName = "Jasin", LastName = "VM"}
};
return View(persons);
}
[HttpPost]
public ViewResult Register(List persons )
{
return View();
}
}
}
Index view code for looping the person collection and also I had put a form tag which map to Register action for posting the edited collection
When we click the register button the form will post the collection of values to Register action like below