Using MVC 5 with a Razor (.cshtml) view
You have a list of values in a model that needs to ultimately get data from a control in the view and append them to the list.
For example:
The model contains: public List<string> value { get; set; }
The List is allowed to contain up to 70 values, but can contain less.
In the view you have a button that dynamically adds @Html.editorfor
fields, much like this:
For each new field that is created, it's corresponding value must be appended to the List<string> value
. So in this example,
The user clicks "Add Field", the new text box appears, and he enters "Line 1"
- When submitted, this field will post to the first index of the value list like so:
value[0] = "Line 1"
The user clicks "Add Field" again to add another value - he enters "Line 2"
- When submitted, this field will post to the second index of the value list like so:
value[1] = "Line 2"
The User can add UP TO 70 fields (i.e He can click "add field" 65 times to add 65 values to the value list)
What would be the quickest and most efficient way to bind the data in this manner?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…