Suppose I have a simple model:
public class studentNames
{
string name{get; set;}
}
Now, if I scaffold it in view by create mode, only one model would be created. I want to create multiple objects in a single view.
Something like:
<form action="someAction">
Name of student1: <student1 name input box>
Name of student2: <student2 name input box>
<save button>
</form>
When this button would be clicked, a List would be returned in the controller, where I would be able to save them in database.
How can I achieve this?
Thanks in advance.
You could start by reading the convention that the model binder expects for
binding to lists. And then name your input fields appropriately:and then your POST controller action could take a collection of students:
If you want to be able to dynamically add and remove items in this collection inside the view I would recommend you reading the
Editing a variable length listarticle from Steven Sanderson where he illustrates a nice technique that would allow you to build such interface.