In my view I have a table with a foreach loop that shows data in my model.
<table id="dt_table_tools" class="table table-striped table-condensed">
<thead>
<tr>
<th>@Html.DisplayNameFor(model => model.ItemOptions.First().Active)</th>
<th>@Html.DisplayNameFor(model => model.ItemOptions.First().ItemOptionCode)</th>
<th>@Html.DisplayNameFor(model => model.ItemOptions.First().Name)</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (ItemDetailItemOptionViewModel ItemOption in Model.ItemOptions)
{
<tr>
<td>@Html.DisplayFor(model => ItemOption.Active)</td>
<td>@Html.DisplayFor(model => ItemOption.ItemOptionCode)</td>
<td>@Html.DisplayFor(model => ItemOption.Name)</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = ItemOption.ItemOptionId })
</td>
</tr>
}
</tbody>
</table>
I then have a modal form that allows me to add new data via an ajax call back to the server, and then it add's a row onto the end of the table to show the new data:
var handleSuccess = function (result) {
if (result.success) {
var $tr = $('<tr>').append(
$('<td>').text(result.Active),
$('<td>').text(result.ItemOptionCode),
$('<td>').text(result.Name),
$('<td>')
).appendTo('#dt_table_tools');
} else {
$('#itemOptionFormContainer').html(result);
}
};
This all works ok with the exception that the new row added to the table does not appear in the same format. For example the 'Active' column shows 'true' instead of the tick box:

How can I get the jquery code to use @Html.DisplayFor(model => ItemOption.Active) so that the data is shown as expected?