Pass List of models to controller ASP.NET MVC 5

Posted by user3697231 on Stack Overflow See other posts from Stack Overflow or by user3697231
Published on 2014-08-24T10:18:04Z Indexed on 2014/08/24 10:20 UTC
Read the original article Hit count: 135

Filed under:
|
|
|

I have a view where user can enter some data. But problem is this: Let's say you have 3 text box on view. Every time user can fill multiple times this 3 text boxes. To clarify, let's say user fills this 3 text boxes and press button which adds on form again these 3 text boxes. Now when user clicks submit this form is sent to controller, but how do I sent List of models as parameter. My architecture for this problem is something like this:

MyModel

public int ID { get;set; }

public string Something { get; set; }

/*This three textboxes can user set multiple times*/
/*Perhaps i Can create new model with these properties and then 
/*put List of that model as property here, but how to fill that list inside view ??*/                   
public string TextBoxOneValue { get; set; }   
public string TextBoxTwoValue { get; set; }
public string TextBoxThreeValue { get; set; }

Now, i was thinking that i Create PartialView with this 3 text boxes, and then when user clicks button on view another PartialView is loaded.

And now, let's say I have Two partial views loaded, and user clicks submit, how that I pass list with values of these 3 text boxes to controller ??

© Stack Overflow or respective owner

Related posts about view

Related posts about model