MVC .NET Model Binding to Array on the fly

后端 未结 2 1715
不知归路
不知归路 2020-12-09 22:56

In Scotts blog post he describes how to post an array of objects to the controller.

My Question how best to generate a View for this that allows th

2条回答
  •  无人及你
    2020-12-09 23:25

    when rendering and binding to lists or arrays, i normally prefer for loop over foreach loop because it will generate required indices for the modelbinder to bind data to the model.

    for(int i=0;i
    }
    

    i m not comfortable with strongly typed helpers when it comes to list binding but its purely a matter of personal preference. However, if you are allowing the user to dynamically add and remove items from page through javascript you have to take care of indices yourself.

    EDIT: i have blogged about creating master detail form in asp.net mvc using jquery templates which is relevant in list binding scenario as well

提交回复
热议问题