I am trying to mount a table by making a request to the server and populating it with the return.
The return of the server is correct, but when it enters the function(data)
, I noticed that it loads all my html
page, I already tried to play the ajax
direct in $(document).ready
, and then use the form it is in below, using load
, but neither is working.
$("#table_horde").Load(
$.ajax({
type: "POST",
url: "/Horde/List/",
success: function (data) {
var cols = "";
for (var i = 0; i < data.length; i++) {
cols += "<tr>";
cols += "<td>" + data[i].NomeHorda + "</td>";
cols += "<td>" + data[i].Limit + "</td>";
cols += "<td><a href='#' onclick='atualizar'(" + data[i].IdHorde + ")' data-target='#janelaHordaCadastro' data-toggle='modal'>Atualizar</a></td>";
cols += "<td><a href='#' onclick='excluir'(" + data[i].IdHorde + ")'>Excluir</a></td>";
cols += "</td>";
}
$("#table_horde tbody").empty();
$("#table_horde tbody").append(cols);
$("#qtdRegistro").html(data.length);
},
error: function (ex) {
alert("Erro: " + ex.status);
}
})
);
My Controller
is as follows:
public ActionResult List() {
return View("List", ListinerHorde());
}
private List<HordeList> ListinerHorde() {
var list = new List<HordeList>();
HordeRepository hr = new HordeRepository();
foreach (var h in hr.FindAll()) {
var model = new HordeList();
model.NameHorde = h.NameHorde;
model.Limit = h.Limit;
list.Add(model);
}
return list;
}
See below the return image: