我有一个使用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>这里是我的C#看起来像的代码片段
var registrationTypeInspectionTypes = new BusinessLayer.RegistrationTypeInspectionType().GetAll(); model.RegistrationTypeInspectionType.RegistrationTypeInspectionTypes = registrationTypeInspectionTypes;当我提交表单时,这些值不会被发送给控制器。
I have a table that is dynamically created using JQuery. I need to pass the IDs of every row in that table to the controller so that I can save the values to the Database. My HTML for the dynamically created rows looks like this
<td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5"> <button class="removeInspectionType" type="button" data-val="5">Remove</button> </td>here is a code snippet of what my C# looks like
var registrationTypeInspectionTypes = new BusinessLayer.RegistrationTypeInspectionType().GetAll(); model.RegistrationTypeInspectionType.RegistrationTypeInspectionTypes = registrationTypeInspectionTypes;when I submit the form these values are not being sent to the controller.
最满意答案
只有输入字段不是表格的td或tr。 请尝试在每个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>现在,当您提交表单时,这些隐藏的字段也将被提交,您可以在控制器中获取这些字段。
Only input fields are submitted not the td or tr of the table. Please try to create hidden fields in each td with the name you want to submit. your table should look like this
<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>Now when you submit the form these hidden fields will also be submitted and you can get these in the controller.
更多推荐
registrationTypeInspectionTypes,RegistrationTypeInspectionType,class,电脑培训,计算机培训,
发布评论