Home >Backend Development >C++ >How to Correctly Map HTML Table Data to an ADO.NET DataTable via Model Binding?
Publish the HTML table value to Ado.net Datatable. The key is to ensure that the HTML control name corresponds to the model attribute.
Correct HTML control to submit the form
The control name generated by the current HTML labeling is incorrect, which hinders the data binding with the model. In order to correctly bind, the control name must be aligned with the attributes of the model. For the first line, you should not use "item.leaveType", but "LeaveDetailsList [0] .leaveType" should be used. For the second line, "LeaveDetailsList [1] .leaveType" should be used.
Modify the html code
In order to achieve this, if the collective is achieved, you can use the for loop, or to realize the collection of EditortEmplate in order to achieve the collection of INUMERABLE .
<code class="language-csharp">for (int i = 0; i < ...; i++) { // 使用 LeaveDetailsList[i].LeaveType 等生成控件 }</code>
In the main view:
<制> The controller code
<code class="language-csharp">@model yourAssembly.LeaveBalanceDetails <tr> <td>@Html.TextBoxFor(m => m.LeaveType)</td> .... </tr></code>
Finally, in the Edit method of the controller:
<code class="language-csharp"><table> .... // 添加表头 <tbody> @Html.EditorFor(m => m.LeaveDetailsList) </tbody> </table></code>
The above is the detailed content of How to Correctly Map HTML Table Data to an ADO.NET DataTable via Model Binding?. For more information, please follow other related articles on the PHP Chinese website!