Passing a dynamic list through POST in asp.net c#

前端 未结 1 654
不思量自难忘°
不思量自难忘° 2021-01-28 19:10

Within my view I need multiple input boxes for a dynamic number of values. For example, if I have a dynamic amount of input boxes (shown here http://jsfiddle.net/skip405/9sX6X/6

相关标签:
1条回答
  • 2021-01-28 19:15

    The process of converting data from request to the action input parameters in the controller is called Model Binding. A lot of flexibility is implemented here, see Model Binding To A List

    The basic idea is that if you have several inputs with the same name, they can be bound to a List<string>.

    more complex scenarios are possible as well: if you have a like

    public class Person
    {
        public int Age{get; set;}
        public string Name{get; set;}
    }
    

    and an action method:

    public ActionResult DoSomething(List<Person> people)
    {
         //do something
    }
    

    the input fields can be like this:

    <input type="number" name="[0].Age" />
    <input type="number" name="[0].Name" />
    <input type="number" name="[1].Age" />
    <input type="number" name="[1].Name" />
    
    0 讨论(0)
提交回复
热议问题