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.
- Host: GitHub
- URL: https://github.com/arnab-developer/collectionmodelbinding
- Owner: Arnab-Developer
- License: mit
- Created: 2020-04-04T05:43:16.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-09T11:53:19.000Z (about 4 years ago)
- Last Synced: 2025-01-17T02:24:18.520Z (5 months ago)
- Language: C#
- Size: 655 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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();
}
```