Home >Backend Development >C++ >How to Convert an HTML Table to an ADO.NET DataTable for Database Storage?
Convert the HTML table to Ado.net DataTable
Detailed explanation
HTML table is generated by looping with Foreach, which creates a row with input fields. The problem is that the name attribute of these input fields does not match the model attribute, and this is necessary for binding to the model when returning.In order to obtain the correct name attribute, you should use the for loop (the collection must implement iList
) or use the custom EditortEMPlate (the collection only needs to realize IenuMerable
Use the custom Editortemplate:
<code class="language-csharp">for (int i = 0; i < Model.LeaveDetailsList.Count; i++) { @Html.TextBoxFor(m => m.LeaveDetailsList[i].LeaveType) .... }</code>
Main view:
Controller:
<code class="language-csharp">@model yourAssembly.LeaveBalanceDetails <tr> <td>@Html.TextBoxFor(m => m.LeaveType)</td> .... </tr></code>
By using one of these methods, you can ensure that the name property of the input field matches the model attribute, so that it can be bound to the model and extract the value from the HTML table.
The above is the detailed content of How to Convert an HTML Table to an ADO.NET DataTable for Database Storage?. For more information, please follow other related articles on the PHP Chinese website!