C# 使用MVC将动态创建的表行的ID传递给控制器

C# 使用MVC将动态创建的表行的ID传递给控制器,c#,html,asp.net-mvc,C#,Html,Asp.net Mvc,我有一个使用JQuery动态创建的表。我需要将该表中每一行的ID传递给控制器,以便将值保存到数据库中。 动态创建的行的HTML如下所示 <td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5"> <button class="removeInspectionType" type="button" data-val

我有一个使用JQuery动态创建的表。我需要将该表中每一行的ID传递给控制器,以便将值保存到数据库中。 动态创建的行的HTML如下所示

<td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5">
    <button class="removeInspectionType" type="button" data-val="5">Remove</button>
</td>
<td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5">
<input type="hidden" name="RegistrationTypeInspectionType.InspectionTypes" value="5"/>
<button class="removeInspectionType" type="button" data-val="5">Remove</button>

当我提交表单时,这些值不会发送到控制器。

仅提交输入字段,而不是表的td或tr。请尝试使用您要提交的名称在每个td中创建隐藏字段。你的桌子应该是这样的

<td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5">
    <button class="removeInspectionType" type="button" data-val="5">Remove</button>
</td>
<td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5">
<input type="hidden" name="RegistrationTypeInspectionType.InspectionTypes" value="5"/>
<button class="removeInspectionType" type="button" data-val="5">Remove</button>

去除


现在,当您提交表单时,这些隐藏字段也将被提交,您可以在控制器中获得这些字段。

仅提交输入字段,而不是表的td或tr。请尝试使用您要提交的名称在每个td中创建隐藏字段。你的桌子应该是这样的

<td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5">
    <button class="removeInspectionType" type="button" data-val="5">Remove</button>
</td>
<td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5">
<input type="hidden" name="RegistrationTypeInspectionType.InspectionTypes" value="5"/>
<button class="removeInspectionType" type="button" data-val="5">Remove</button>

去除


现在,当您提交表单时,这些隐藏字段也将被提交,您可以在控制器中获得这些字段。

我确实找到了一篇与您发布的内容类似的文章。我现在就要试试这个。。。我感觉它会起作用的。我会马上更新的,如果对你有帮助的话,那太好了。谢谢你的帮助!这起作用了。现在我只需要修复我的代码lol的其余部分。我真的找到了一篇与你发布的内容类似的文章。我现在就要试试这个。。。我感觉它会起作用的。我会马上更新的,如果对你有帮助的话,那太好了。谢谢你的帮助!这起作用了。现在我只需要修复我的代码lol的其余部分。