I am new to the forum and I have broken my head all day because I can not solve this. I would greatly appreciate your help.
I have a very simple application in c # .net. I need to generate a table from a json that (according to me) contains the information of a query to the database (SQL SERVER). The table should appear when clicking on another main table that is in the view; From there, he grabs the ID to consult the BD. I am trying to generate the table with jquery, the other table is generated automatically with the model (Entity Framework). I hope I have been specific, here I leave part of my code to see if you understand a little better the idea:
MODEL
public class ApCommentView
{
[Key]
public int id_comment { get; set; }
public int id_app { get; set; }
public string version_app { get; set; }
public string comentario { get; set; }
}
MANAGER
public class ApCommentManager
{
LogBDEntities1 bd = new LogBDEntities1();
public List<app_comments> idSearch(int id_ap)
{
var result = from c in bd.app_comments where
c.id_app.Equals(id_ap)
select c;
return result.ToList();
}
}
CONTROLLER
[HttpPost]
public JsonResult Search(int id)
{
ApCommentManager ACM = new ApCommentManager();
var results = ACM.idSearch(id);
return Json(results);
}
VIEW
<script type="text/javascript">
$(document).ready(
function BUSCARid() {
var tr = $('#dataApp').find('tr');
tr.bind('click', function (event) {
var row = $(this).closest('tr');
var id_app = row.find("td:eq(0)").html().trim();
alert(id_app);
$.ajax({
type: "POST",
url: '@Url.Action("Search","Home")',
data: { id : id_app },
success: function () {
alert("OK");
$("#resultado").html('');
for (var i = 0; i < result.length; i++) {
$("#resultado").append("<li> " + result[i].id_app + " " + result[i].version_app + " " + result[i].comentario + " </li>");
//}
},
error: function (xhr) {
//debugger;
console.log(xhr.responseText);
alert("Error has occurred..");
}
});
});
});
PS: The view where I want to generate the table refers to the model where the main table comes from, I do not know if that affects something.