An open API service indexing awesome lists of open source software.

https://github.com/arnab-developer/collectionmodelbinding

Collection model binding with asp.net core.
https://github.com/arnab-developer/collectionmodelbinding

Last synced: 3 months ago
JSON representation

Collection model binding with asp.net core.

Awesome Lists containing this project

README

        

# ASP.NET Core model binding with collection

`SessionController` `Index` method is sending a `Student` collection to view.

```csharp
public IActionResult Index()
{
var s = new Session()
{
Id = 1,
Name = "session1",
Students = new List()
{
new Student()
{
Id = 1,
Name = "student1"
},
new Student()
{
Id = 2,
Name = "student2"
}
}
};
return View(s);
}
```

In the view it uses the ASP.NET model binding to post data into `Create` method.

```html




@for(var i = 0; i < Model.Students.Count; i++)
{




}

```

```csharp
public IActionResult Create(Session s)
{
return View();
}
```