I'm trying to retrieve my data from a database using jQuery AJAX. I can't figure out what's wrong in my code. I think i did some mistake in the script section of the code. Any help would be most appreciated
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.userName)
</th>
<th>
@Html.DisplayNameFor(model => model.password)
</th>
</tr>
</thead>
<tbody id="AdminList">
<tr id="loadingStatus" style="color:red">
</tr>
</tbody>
</table>
$("#loadingStatus").html("Loading...");
$.get("/Admins/GetAdminData", null, DataBind);
function DataBind(AdminList) {
var setData = $("#AdminList");
for (var i = 0; i < AdminList.length; i++) {
var Data = "<tr class='row_" + AdminList[i].empid + "'>" +
"<td>" + AdminList[i].username + "</td>" +
"<td>" + AdminList[i].password + "</td>" +
"<td>" + "<a href='#' class='btn btn-warning' onclick='EditRecord(" + AdminList[i].empid + ")' ><span class='glyphicon glyphicon-edit'></span></a>" + "</td>" +
"<td>" + "<a href='#' class='btn btn-danger' onclick='DeleteRecord(" + AdminList[i].empid + ")'><span class='glyphicon glyphicon-trash'></span></a>" + "</td>" +
"</tr>";
SetData.append(Data);
$("#LoadingStatus").html(" ");
}
}
public JsonResult GetAdminData()//needs fixing
{
List<Admin> ad = new List<Admin>();
var dat = db.Admins.Select(x => new {
empid = x.empId,
username = x.userName,
passWord = x.password
}).ToList();
//foreach(DataRow dr in)
//{
// ad.Add(new Admin
// {
// userName =
// });
//}
return Json(dat, JsonRequestBehavior.AllowGet);
}
case sensitive issue i changed
password = x.password