user516883
user516883

Reputation: 9378

Filling model list property in mvc

I have a model with a list property. In my view the user will fill in a fixed number of similar data (name number etc). How can I collect that information and create a list of it on the post? Thanks for any help.

public class mainonject
{
    public List<test> list{ get; set; }
}

public class test
{
    string name;
    string number;
}

<form>
    HOW DO I COLLECT THE PROPERTY list AS A LIST TO THE SERVER
    <input type="submit" value="submit"/> 
</form>

Upvotes: 3

Views: 1307

Answers (1)

Jan
Jan

Reputation: 16032

Just add the fields to your form and use the right indexes in there name properties:

<input name="list[0].Name" type="text" />
<input name="list[0].Number" type="text" />

<input name="list[1].Name" type="text" />
<input name="list[1].Number" type="text" />

...

Upvotes: 1

Related Questions