I have the following code in my controller
:
public JsonResult List(string nome){
IList<ClienteDto> clientes = string.IsNullOrEmpty(nome)
? _repositoryCliente.Get()
: _repositoryCliente.GetByName(nome);
var model = Mapper.Map<IList<ClienteDto>, IList<ClienteViewModel>>(clientes);
return Json(model, JsonRequestBehavior.AllowGet);
}
and this is my JS:
function Search(name) {
$.ajax({
url: "/Cliente/List/?nome=" + name,
type: "POST",
dataType: "json",
success: function (clientes) {
$("#tableClientes").empty();
url: "/Cliente/Lister/model=" + clientes;
},
});
}
and here is the view code:
<table class="table" id="tableClientes">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.ClienteId)
</th>
<th>
@Html.DisplayNameFor(model => model.Nome)
</th>
<th>
@Html.DisplayNameFor(model => model.DataNascimento)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Telefone)
</th>
<th>
@Html.DisplayNameFor(model => model.Situacao)
</th>
</tr>
</thead>
@foreach (var item in Model)
{
<tbody id="tbody">
<tr id="[email protected]">
<td>
@Html.DisplayFor(modelItem => item.ClienteId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Nome)
</td>
<td>
@item.DataNascimento.ToShortDateString()
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.Telefone)
</td>
<td>
@Html.DisplayFor(modelItem => item.Situacao)
</td>
<td></td>
<td>
<a href="@Url.Action("Edit", "Cliente", new { id = @item.ClienteId })">
<span class="glyphicon glyphicon-edit" />
</a>
<i class="glyphicon glyphicon-trash" onclick="ModalRemove(@item.ClienteId);" />
</td>
</tr>
</tbody>
}
</table>
Everything works fine, the search is done and returns a JSON object with the searched data, however I do not know how to update my table
with this data.
How could I do that?