MVC Form表单提交“list”数据,后台如何接收

时间:2022-12-09 17:24:03
<a href="javascript:void(0)" id="Inventory_add" class="layui-btn layui-btn-lg layui-btn-normal" style="margin:30px 0px;">新增类型</a>
<table id="table-User">
                            <thead>                                
                                <th>车身颜色</th>
                                <th>内饰颜色</th>
                                <th>库存数量</th>
                                <th>操作</th>
                            </thead>
                            <tbody>
                                <tr>                                    
                                    <td>@Html.TextBox("BodyworkColor","",new { @name="list[0].BodyworkColor",@class="layui-input",@data_name="车身颜色"})</td>
                                    <td>@Html.TextBox("AutomotiveTrimColor","",new { @name="list[0].AutomotiveTrimColor",@class="layui-input",@data_name="内饰颜色"})</td>
                                    <td>@Html.TextBox("InventoryNumber","",new { @name="list[0].InventoryNumber",@class="layui-input",@data_name="库存数量"})</td>
                                    <td><a href="javascript:void(0)" class="layui-btn layui-btn-xs layui-btn-danger btn_remove">删除</a></td>
                                </tr>
                            </tbody>
                        </table>
$("#Inventory_add").click(function () {
            var number = $("#table-User tbody tr").length;
            var html = '<tr><td><input class="layui-input" id="BodyworkColor" data-name="车身颜色" name="list[' + number + '].BodyworkColor" type="text" value=""></td>';
            html += '<td><input class="layui-input" id="AutomotiveTrimColor" data-name="内饰颜色" name="list[' + number + '].AutomotiveTrimColor" type="text" value=""></td>';
            html += '<td><input class="layui-input" id="InventoryNumber" data-name="库存数量"  name="list[' + number + '].InventoryNumber" type="text" value=""></td>';
            html += '<td><a href="javascript:void(0)" class="layui-btn layui-btn-xs layui-btn-danger btn_remove">删除</a></td></tr>';
            $("#table-User tbody").append(html)              
        })

那么我的后台改用什么接收整个值?From表单提交

2 个解决方案

#1


后台接收的参数名就是list

#2


1、Request[""]
2、action(string a,string b)  <input name="a "> <input name="b ">
3、FormCollection
4、action(Model m)

#1


后台接收的参数名就是list

#2


1、Request[""]
2、action(string a,string b)  <input name="a "> <input name="b ">
3、FormCollection
4、action(Model m)