How do you handle the output of a dynamically generated form in ASP.NET MVC?

后端 未结 4 1789
失恋的感觉
失恋的感觉 2020-12-19 18:00

Say you create a form using ASP.NET MVC that has a dynamic number of form elements.

For instance, you need a checkbox for each product, and the number of products ch

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 18:08

    Per Craig's answer.. that is safer. There are quirks to posting multiple form elements with the same name. I would add that it would be wise to wrap the logic that makes the "collection" of controls in a way similar to WebForms. Web Forms prepend the container control's name and adds an index. For example, in a Repeater the form elements inside would be named (something like) RepeaterName_Element1, RepeaterName_Element2. When you go to get the elements out, you have to use FindControl or something of the sort.

提交回复
热议问题